15 Mar 2011 01:29
Calling a list of methods in Ruby
I have some code with an array of method names, and I want to call
each method in turn. Right now, I have:
[ :foo, :bar, :baz ].each { |the_method|
some_object.method(the_method).call }
which works. However, the whole method(x).call chain seems like the
long way around this particular issue. AFAICT, Ruby doesn't really
support indirect variables like bash does (e.g. the ${!foo} construct)
so I'm not sure how to do this in a less bizarre way.
Anyone know the Ruby Way to do this?
RSS Feed