K
K
krosh2017-01-17 11:21:35
ruby
krosh, 2017-01-17 11:21:35

How to get the name of a method within itself?

How to get the name of the method inside a method?

def double(n)
  puts n*n
  # puts имя_метода
end

double(2)

#4
#double

I want to use for debugging. There will be many methods of the same type that are called according to certain logic.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
N. Bekseitov, 2017-01-17
@krosh

def double(n)
  puts n*n
  puts __callee__
end

double(2)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question