Created
December 17, 2010 08:00
-
-
Save rogercampos/744644 to your computer and use it in GitHub Desktop.
Return the calling method. This version also works when the call was from inside a block.
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
def this_method | |
caller[0] =~ /`([^']*)'/ and $1 | |
end | |
# This one only works in ruby 1.8.x, see the other file for 1.9 version | |
def calling_method(depth = 1, file = "") | |
caller[depth] =~ /^(.+?):(\d+)(?::in `(.*)')?/ | |
if $3 && ($1 == file || depth == 1) | |
$3 | |
else | |
file = $1 if depth == 1 | |
calling_method(depth+1, file) | |
end | |
end |
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
def calling_method | |
caller[1] =~ /^(.+?):(\d+)(?::in `(.*)')?/ | |
res = $3 | |
res = res.split(" ").last if res.include?("block in") | |
res | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment