Jano Svitok
8/23/2006 4:44:00 PM
On 8/23/06, Dikshit Saumya-G19445 <somc@motorola.com> wrote:
> Hi
> I am a newbie to this mailing list.
>
> I have a couple of queries:
>
> 1. Can methods be part of an array definition, which can bear similarity
> to 'C' definitions
> of "array of function pointers", as part of a state machine
> implementation.
Look up Object#method and Method in the docs:
you can do ['aaa'.method(:size), 10.method("+")]
UnboundMethod could be useful as well.
Other than that, its possible to call methods by name. I you just need
to call methods on one object, it is enough to store just their names
(preferably as symbols):
methods = [:size, :length, :whatever]
then you would for example do: methods.each {|m| 'aaaa'.send(m) }