Skip to content

Instantly share code, notes, and snippets.

@nagachika
Last active August 29, 2015 14:09
Show Gist options
  • Save nagachika/c2b3b35bafbf81df2d25 to your computer and use it in GitHub Desktop.
Save nagachika/c2b3b35bafbf81df2d25 to your computer and use it in GitHub Desktop.
class A
Const = lambda{ p [ :in_lambda, self, @foo ] }
define_method(:meth) do
p [:in_method, self, @foo]
Const.call
end
def initialize
@foo = 72
end
end
A.new.meth
# Result:
# => [:in_method, #<A:0x007f8f690117d8 @foo=72>, 72]
# => [:in_lambda, A, nil]
class A
Const = lambda{ p [ :in_lambda, self, @foo ] }
define_method(:method_from_lambda, &Const)
def initialize
@foo = 72
end
end
A.new.method_from_lambda
# => [:in_lambda, #<A:0x007f8f69011468 @foo=72>, 72]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment