Tim Hunter
3/14/2007 1:59:00 AM
ajtwatching wrote:
> Hey folks,
>
> Like many posts have no doubt started.. I'm giving this ruby business
> a crack!! ;)
>
> Now this might be a really bad approach.. but I'll throw it out there.
>
> Here's my simple class.
>
> class Myclass
> def initialize
> end
>
> def hello
> puts "hello"
> end
>
> def bye
> puts "bye"
> end
> end
>
> As expected, works a treat.
>
> friendly = Myclass.new
> friendly.hello
> friendly.bye
>
> Now, given I now what methods are available, is there a way to do
> something similar to this...
>
> methods = ['hello', 'bye']
> methods.each { |m| friendly.m }
>
> Regards,
>
> ajt.
>
>
>
Look up the __send__ method:
obj.__send__("methodname", arg1, arg2)