how to define methods dynamically using define_method

0 views
Skip to first unread message

Venkat Bagam

unread,
Oct 30, 2007, 9:12:28 AM10/30/07
to rubyonra...@googlegroups.com
Hi Folks,

I have an array has_roles = %w[admin employee ...] which is a subset of
application_roles = ["admin", "employee", "manager"...]
Now I would define a method for each role in application roles where i
would call methods like

@logged_in_user.admin which returns true because has_roles
includes "admin"
@logged_in_user.employee which returns true because has_roles
includes
"employee"
@logged_in_user.manager which returns false because has_roles
doesnot
include "manager"

I came accross using define_method in class Module for this purpose but
went wrong some where. Can any one there achieve this using
define_method. Its very urgent any help appreciated..thanks in
advance...
--
Posted via http://www.ruby-forum.com/.

Reply all
Reply to author
Forward
0 new messages