From: ara.t.howard@... Date: 2006-02-05T12:46:26+09:00 Subject: Re: define_method with a &block? On Sun, 5 Feb 2006, Erik Veenstra wrote: > In the code below, I want test2 to receive a block, like test1, > so they do the same. Is that possible? > > (I use this "define_method" in meta-programming code. Using > "def" is not an option.) > > Thanks. > > gegroet, > Erik V. - http://www.erikveen.dds.nl/ > > ---------------------------------------------------------------- > > class Test > def test1(*args, &block) > p [:test1, args, block_given?] > end > > define_method(:test2) do |*args| > p [:test2, args, block_given?] > end > end > > Test.new.test1(1, 2, 3){} > Test.new.test2(1, 2, 3){} harp:~ > cat a.rb class Test def test1(*args, &block) p [:test1, args, block_given?] end module_eval <<-def def test2 *args p [:test2, args, block_given?] end def end Test.new.test1(1, 2, 3){} Test.new.test2(1, 2, 3){} harp:~ > ruby a.rb [:test1, [1, 2, 3], true] [:test2, [1, 2, 3], true] hth. -a -- happiness is not something ready-made. it comes from your own actions. - h.h. the 14th dali lama