Created
March 22, 2012 05:31
-
-
Save rondale-sc/2156399 to your computer and use it in GitHub Desktop.
caller-method
This file contains hidden or 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
| 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