From: Daniel Brockman Date: 2005-08-10T19:48:31+09:00 Subject: Re: passing a method Hi Wybo, > I want to make a method which can execute another method > given to it as an argument. Why do you want to do this? > The following works but the call doesn't look elegant - > is it the ruby way? It's difficult to tell based on your contrived example, but the Ruby way would probably be more like this: def doit yield end doit { hello } doit { bye } doit { hello } You can write `doit { hello }' as `doit &method(:hello)' if you really want to, but the general block syntax is obviously much more flexible. > wybo>cat test.rb > #!/usr/bin/env ruby > @t = '' > def bye > @t << 'bye' > end > def hello > @t << 'hello' > end > def doit(f) > f.call > end > doit(method(:hello)) > doit(method(:bye)) > doit(method(:hello)) This is a rather poor example, since the above three lines could just as well be written like this: hello bye hello > puts @t > wybo>ruby test.rb > hellobyehello > wybo> -- Daniel Brockman So really, we all have to ask ourselves: Am I waiting for RMS to do this? --TTN.