Brian Candler wrote:
> You can use a block (non-string) eval, which isn't quite as short but 
> avoids the 'send'. It's nicer if you have a whole bunch of define_method 
> calls.
> 
>   @cars.each do |owner, model|
>     widget = TkLabel.new(:text => model)
>     (class << widget; self; end).class_eval do
>       define_method(:get_owner) do
>         owner
>       end
>     end
>   end

Thanks. I tried to shorten it to:

   @cars.each do |owner, model|
     widget = TkLabel.new(:text => model)
     class << widget
       define_method(:get_owner) do
         owner
       end
     end
   end

But it turns out that 'class', just like 'def', cuts off the inner code 
from the variables outside.

-- 
Posted via http://www.ruby-forum.com/.