Ruby1.9 Call Method

Like __callee__ , is there something that the calling method returns? I understand that there is a caller that I would like to remove from the name of the calling method, but I'm curious if there is a standard method to return the name of the calling method without any other information with it.

+4
source share
1 answer

There is no such function in MRI. But there are several alternatives.

If you use Rubinius, you can do this instead of parsing caller :

 Rubinius::VM.backtrace(1, false).first.name #=> :calling_method_name 

You can also use the gem to analyze the caller result for you. It should work for any Ruby> 1.9.

The answer to this SO question describes how you can do a simple analysis yourself.

And finally, it seems that work is ongoing to get such a feature in Ruby 2.0, although the corresponding ticket has not been updated for some time.

+2
source

Source: https://habr.com/ru/post/1402058/


All Articles