From: Brian Candler Date: 2007-03-25T21:48:12+09:00 Subject: Re: pointer to function On Sun, Mar 25, 2007 at 09:10:12PM +0900, ekkehard.horner wrote: > my %Fncs = ( 'frsFnc' => [ 'just tell "frsFnc"', \&frsFnc ] > , 'secFnc' => [ 'just tell "secFnc"', \&secFnc ] > ); You have several options, depending on how literally you want to translate this. # (1) this is a Method object which is bound to the current object. Use # fncs['frsFnc'][1].call(args...) # to invoke it fncs = { 'frsFnc' => [ 'just tell "frsFnc"', method(:frsFnc) ], } # (2) this is a Symbol giving the *name* of a method. Use # some_object.send(:method, args...) # to invoke it on an arbitary object (which could be 'self') fncs = { 'frsFnc' => [ 'just tell "frsFnc"', :frsFnc ], } # (Note: this means you may not need to build the fncs hash at all; just let # the caller pass in a method name. This assumes you don't mind the caller # being able to call *any* method on your object) # (3) this is an anonymous function, like "sub { ... }" in Perl. Use # fncs['frsFnc'][1].call(args...) # to invoke it. fncs = { 'frsFnc' => [ 'just tell "frsFnc"', proc { puts "hello" } ], } A fourth option is to put the callable methods in a Module. Use Modname.instance_method(:method_name) to get an 'unbound method' object, which is like a method but not bound to a specific object instance. You then have to bind it to a particular object when you call it. There are probably others :-) HTH, Brian.