0

I need to find which method called "abc", based on that I can do some operations.

Class A
  def method1
   abc
  end

  def method2
   abc
  end

  def abc
   puts "abc" if calling_method == :method1
   puts "xyz" 
  end
end

Is this possible in ruby?

sjain
  • 23,126
  • 28
  • 107
  • 185
  • 2
    possible duplicate of [How to get the name of the calling method?](http://stackoverflow.com/questions/5100299/how-to-get-the-name-of-the-calling-method) – sawa Mar 02 '13 at 12:16
  • 1
    Sorry Sawa, I tried to find the question but could not find It. I got my answer from the link. – Abibullah Rahamathulah Mar 02 '13 at 12:29

1 Answers1

4

You can use the caller() method.

http://www.ruby-doc.org/core-2.0/Kernel.html#method-i-caller

gmaliar
  • 5,294
  • 1
  • 28
  • 36