Joel VanderWerf
5/17/2008 8:20:00 PM
Leon Bogaert wrote:
> I thought I understood the block/proc thing. Guess not...
>
> I thought when I proc is converted to a block, the code gets evaluated.
> So (I thought) when Proc.call() is, euhm, called, the proc gets
> converted to a block and is getting evaluated in that context.
The block keeps the original context ("lexical scoping"), including
local vars, self, and constants:
class C
class D; end
def foo
local = 1
proc { [local, self, D] }
end
end
class D; end
local = 2
p [local, self, D]
p C.new.foo.call
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407