Created
December 5, 2014 10:42
-
-
Save ldonnet/78addbcbbc3559cfdc6a to your computer and use it in GitHub Desktop.
Get method caller
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
| def caller_method_name | |
| parse_caller(caller(2).first).last | |
| end | |
| def parse_caller(at) | |
| if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at | |
| file = Regexp.last_match[1] | |
| line = Regexp.last_match[2].to_i | |
| method = Regexp.last_match[3] | |
| [file, line, method] | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment