From: Dave Thomas Date: 2000-07-12T08:31:47-05:00 Subject: [ruby-talk:03951] Re: Pluggable functions and blocks Aleksi Niemel� writes: > class Foo > def Foo.foo > puts "foo" > end > def do_foo( foo = proc {Foo.foo} ) > foo.call > end > end > > def my_foo > puts "bar" > end > > Foo.new.do_foo > Foo.new.do_foo( proc {my_foo} ) # I'd like to say do_foo( my_foo ) > > This seems to work, outputting 'foo\nbar\n' as expected. It's tedious > anyway, and tediousness will turn into error-prone code later. The main > problem is to have explicit proc wrappings over functions. You could just associate a block with the call instead. That makes the call syntax a lot neater. class Foo def Foo.foo puts "foo" end def do_foo(&foo) foo = proc { Foo.foo } unless foo foo.call end end def my_foo puts "bar" end f = Foo.new f.do_foo f.do_foo { my_foo } I'll look through the rest later. All these foo's are hurting my eyes. Dave