Skip to content

Instantly share code, notes, and snippets.

@rogercampos
Created December 17, 2010 08:00
Show Gist options
  • Save rogercampos/744644 to your computer and use it in GitHub Desktop.
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.
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
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