Abibullah Rahamathulah
Abibullah Rahamathulah

Reputation: 2891

Find which method called current method in a model with ruby

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?

Upvotes: 0

Views: 811

Answers (1)

gmaliar
gmaliar

Reputation: 5479

You can use the caller() method.

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

Upvotes: 4

Related Questions