From: Robert Klemme Date: 2005-08-29T23:22:06+09:00 Subject: Re: Calling object method from variable 2005/8/29, Frodo Larik : > Hi all, > > I have two questions regarding object methods > > 1. Is it possible to call a method from a variable? > Something like this: > > i_am_just_a_var = 'this_is_the_real_method' > o = Object.new > o.#{i_am_just_a_var} = 'some thing I want' o.send("#{i_am_just_a_var}=", 'some thing I want') > 2. What is the best way to check for a method of an object? > > After playing around in irb I came up with this: > > o = Object.new > if ( o.methods.grep(/^some_method_name$/ ) > # do stuff > else > # do something else > end o.respond_to? :foo o.send(:respond_to?, i_am_just_a_var) Cheers robert