On Tue, 20 Sep 2005, Pit Capitain wrote:

>> any ideas?
>
> Tom (aka Trans) recently mentioned that he changed procs into methods in
> order to get what you want. Here's a quick hack, not efficient and not
> thread-safe, but maybe a start:
>
>  class Object
>    def arg_instance_eval( *args, &block )
>      c = class << self; self; end
>      c.send( :define_method, :arg_instance_eval_method, &block )
>      arg_instance_eval_method( *args )
>    ensure
>      c.send( :remove_method, :arg_instance_eval_method )
>    end
>  end
>
>  b = lambda{|x| p [x, y]}
>
>  class C
>    def y; 42; end
>  end
>
>  c = C::new
>  z = 41
>
>  c.arg_instance_eval( z, &b )  # => [41, 42]

that's funny.   here's my current hack:

   class Object
     def evaluate(*a, &b)
       ret, sent = nil
       loop do
         m = "____evaluate____#{ rand(42) }____#{ rand(42) }____"
         klass = Class === self ? self : self::class
         begin
           klass.module_eval{ define_method m, &b }
           ret = send(sent = m, *a)
         ensure
           begin
             klass.module_eval{ remove_method m }
           ensure
             break if sent
           end
         end
       end
       ret
     end
   end

   class C
     def y
       42
     end
   end

   b = lambda{|x| p [x, y, self]}

   c = C::new
   x = 42
   c.evaluate(x, &b)  #=> [42, 42, #<C:0xb7f2f5c0>]

guess that's the way to go for now.


cheers.

-a
-- 
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze.  --Nagarjuna
===============================================================================