Skip to content

Instantly share code, notes, and snippets.

@banister
Created June 6, 2012 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banister/2885303 to your computer and use it in GitHub Desktop.
Save banister/2885303 to your computer and use it in GitHub Desktop.
[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