From: Kent Dahl Date: 2002-10-31T16:59:23+09:00 Subject: Re: Runtime access to the source code of a block? Bulat Ziganshin wrote: > i think you need method to COMPILE string into block, like: > > block = compile("{|x| x*2}") > p block.call(2) #=>4 Doesn't eval suffice for this? As for a potential hack for the OP, what about something like this: class X def first_definition( &binding ) @binding ||= binding source = binding.call redefine( source ) end def redefine( source ) @source = source @block = eval "Proc.new { #{source} }", @binding end def x(i) @block.call(i) end end x = X.new a = 3 x.first_definition { %{|i|a+i} } puts x.x(2) #=> 5 x.redefine %{|i|a-i} puts x.x(2) #=> 1 # Ugly enough syntax to know that there is some bad mojo going on atleast :-) -- (\[ Kent Dahl ]/)_ _~_ __[ http://www.stud.ntnu.no/~kentda/ ]___/~ ))\_student_/(( \__d L b__/ NTNU - graduate engineering - 5. year ) ( \__\_�|�_/__/ ) _)Industrial economics and technological management( \____/_�_\____/ (____engineering.discipline_=_Computer::Technology___)