From: "Anders Engström" Date: 2004-11-25T16:32:06+09:00 Subject: Re: proc to method On Thu, Nov 25, 2004 at 04:18:04PM +0900, itsme213 wrote: > I have some closure context captured in a proc, and want to create a method > on a class from that. What is a good way to do this? > Something like the following should work: class Test # The class to add the method to. end # The proc we want to turn into a method block = proc {|arg| puts "Proc got #{arg}" } # Define the method Test.__send__(:define_method, :run_proc, &block) # Make it public Test.__send__(:public, :run_proc) # test it test = Test.new test.run_proc "Hello" //Anders -- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Anders Engstr�m aengstrom@gnejs.net . http://www.gnejs.net PGP-Key: ED010E7F . [Your mind is like an umbrella. It doesn't work unless you open it.]