2

Possible Duplicate:
How to get the name of the calling method?

How do I tell what method called foo in the following example?

class Example
  def initialize
  end

  def foo
    puts "Hello World"  
  end

  def bar
    foo 
  end

  def cats
    bar      
  end
end

Example.new.cats prints bar. I am trying to get the whole callstack. E.g. cats -> bar -> foo

Update:

This works: puts caller[0..1]

Hello World
(irb):11:in `bar'
(irb):15:in `cats'
Community
  • 1
  • 1
atmorell
  • 3,052
  • 6
  • 30
  • 44

1 Answers1

5

Use for instance: puts caller[0] This will give you info for the caller.

Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176