Skip to content

Instantly share code, notes, and snippets.

@rondale-sc
Created March 22, 2012 05:31
Show Gist options
  • Select an option

  • Save rondale-sc/2156399 to your computer and use it in GitHub Desktop.

Select an option

Save rondale-sc/2156399 to your computer and use it in GitHub Desktop.
caller-method
command "caller_method" do |depth|
depth = depth.to_i || 1
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ caller(depth+1).first
file = Regexp.last_match[1]
line = Regexp.last_match[2].to_i
method = Regexp.last_match[3]
output.puts [file, line, method]
end
end
# If you don't want to use pry
# you can try this method anyways like so
def caller_method(depth)
depth = depth.to_i || 1
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ caller(depth+1).first
file = Regexp.last_match[1]
line = Regexp.last_match[2].to_i
method = Regexp.last_match[3]
return [file, line, method]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment