What’s The Name of Method?
Someone asked me today how do I find out what method the current line of code is in during the runtime. Besides the obvious question, I nevertheless thought that it’s interesting that Ruby provides with that information.
Take a look at the code below.
The output is “hello”, which happens to be the name of the method that was called. If you do “__method__.inspect”, then you’ll get :hello instead of the String version.