B
Brian Candler
Hmm, I'm probably being obtuse here, but how do I get a reference to "this
code block" within a code block? I can write:
a = lambda { |x| x < 2 ? 1 : x * a.call(x-1) }
# trouble is, the block is bound to external variable 'a'
b = a
a = nil
puts b.call(5) # fails
I want the object to be self-contained. 'self' doesn't work. Best I can come
up with is to try and hide it:
a = __myfoo = lambda { |x| x < 2 ? 1 : x * __myfoo.call(x-1) }
Is there a better way that this?
Thanks,
Brian.
code block" within a code block? I can write:
a = lambda { |x| x < 2 ? 1 : x * a.call(x-1) }
# trouble is, the block is bound to external variable 'a'
b = a
a = nil
puts b.call(5) # fails
I want the object to be self-contained. 'self' doesn't work. Best I can come
up with is to try and hide it:
a = __myfoo = lambda { |x| x < 2 ? 1 : x * __myfoo.call(x-1) }
Is there a better way that this?
Thanks,
Brian.