Thanks, that's quite enough . I read through this and I agree its quite
an extensive exploration of 'closure-things'.
I think the answer to my question, then is: define_method cannot define a
method that accepts a block passed implicitly or using the '&'.
define_method can define a method that explicitly accepts a 'closure-thing':
define_method('func') do |p1, closure|
...
closure.call ..
..
end
used this way:
obj.func(1, lambda( {puts "hello"}))
NOT this way:
obj.func(1) {puts "hello"} # the way I wanted
Regards,
John
···
On Jun 13, 9:40 am, "John J. Franey" <jjfra...@verizon.net> wrote:
In ruby 1.8, blocks can't accept a block. This feature has been added in 1.9.
If you need to dynamically define methods which take blocks in 1.8, I
think you'll need to use #class_eval / #module_eval either with a
block with defs in it (less useful, since locals outside the block
aren't accesible inside the defs), or with a string argument (with the
usual caveats about evalling strings which might be generated from
user input).
George.
···
On 6/15/07, John J. Franey <jjfraney@verizon.net> wrote:
I think the answer to my question, then is: define_method cannot define a
method that accepts a block passed implicitly or using the '&'.