Created
June 6, 2012 22:45
-
-
Save banister/2885303 to your computer and use it in GitHub Desktop.
This file contains 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
[1] (pry) main: 0> class SomeClass | |
[1] (pry) main: 0* def hello | |
[1] (pry) main: 0* SomeOtherClass.new.beta | |
[1] (pry) main: 0* end | |
[1] (pry) main: 0* end | |
=> nil | |
[2] (pry) main: 0> class SomeOtherClass | |
[2] (pry) main: 0* def beta | |
[2] (pry) main: 0* puts "my method name is #{__method__} inside the #{self.class} class" | |
[2] (pry) main: 0* puts "and my caller is the #{binding.of_caller(1).eval('self.class')} class" | |
[2] (pry) main: 0* end | |
[2] (pry) main: 0* end | |
=> nil | |
[5] (pry) main: 0> require 'binding_of_caller' | |
=> true | |
[6] (pry) main: 0> SomeClass.new.hello | |
my method name is beta inside the SomeOtherClass class | |
and my caller is the SomeClass class | |
=> nil | |
[7] (pry) main: 0> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment