From: "Søren Andersen" Date: 2007-10-25T00:31:29+09:00 Subject: Passing methods as parameters - the nice way? ------=_Part_6267_5739096.1193239887626 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello all, I'm pretty new to ruby, but have some background in Java, and very little C(++) and suchlike. I'm currently - as a "learning-by-doing"-project - creating a simple text-based interface for running (more or less) arbitrary programs. I decided on a simple tree-based structure for the menu itself, however I'm a bit stuck on the hook between my interface, and the program running behin= d it. In order to not couple my interface too tightly to my program running behin= d it, I'd really like for my interface to not know what it's actually interfacing with. Basically, I just figured I could take a leaf from the Functional-programming style and give my TextInterface a method to call whe= n I told it to: def call_action if(@action_method) send(@action_method) end end which works fine, as long as my method is defined "in the wild": def foo puts "foo called" end interface.set_action(:foo) interface.call_action =3D> foo called but, how do I handle it if the method is an instance method on some object? program =3D Program.new interface.set_action(:program.foo)? No variant of this works for me. I realise I may be fundamentally wrong in my approach, so any tips would be welcome. :-) Regards, S=F8ren Andersen ------=_Part_6267_5739096.1193239887626--