Created
April 21, 2012 11:12
-
-
Save brainopia/2436656 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# eval with method definition is used to prevent warnings in some situations | |
DEFINEE = <<-CODE | |
eval 'def __; end' | |
it = method(:__).owner rescue instance_method(:__).owner | |
eval 'undef __' | |
it | |
CODE | |
self # => main | |
eval DEFINEE # => Object | |
class Foo | |
self # => Foo | |
eval DEFINEE # => Foo | |
def bar | |
self # => instance of Foo | |
eval DEFINEE # => Foo | |
end | |
end | |
Foo.instance_eval do | |
self # => Foo | |
eval DEFINEE # => singleton class of Foo | |
end | |
Foo.class_eval do | |
self # => Foo | |
eval DEFINEE # => Foo | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment