Brian Adkins
10/17/2008 6:36:00 AM
Rolando Abarca <funkaster@gmail.com> writes:
> is there a way to specify the binding of a proc created through lambda?
>
> eg:
>
> $ cat test.rb
> class A
> attr_reader :foo
> def initialize
> @foo = lambda { do_that_thing }
> end
> end
>
> class B
> def do_that_thing
> puts "yeah, do it!"
> end
>
> def initialize
> a = A.new
> a.foo.call
> end
> end
>
> B.new
>
>
> So... is there a way to call the lambda defined in A with the binding
> of B?
> thanks a lot for any hint...
Can you provide more context regarding what you're trying to
accomplish? Or are you simply wanting to learn more about Ruby's
semantics?
For example, parameterizing the lambda may do what you want more
simply:
class A
attr_reader :foo
def initialize
@foo = lambda {|x| x.do_that_thing }
end
end
class B
def do_that_thing
puts "yeah, do it!"
end
def initialize
A.new.foo.call(self)
end
end
B.new