2

I have a line of Ruby-code with overloading methods. I want to show the call stack of the line. I don't know the place for caller or byebug. I want to show the current call stack for the line after execution and find the place for debugging. How can I do it?

Approximately like caller Test.method, and after that:

    from /var/lib/gems/2.3.0/gems/railties-4.2.3/lib/rails/commands/console.rb:110:in `start'
    from /var/lib/gems/2.3.0/gems/railties-4.2.3/lib/rails/commands/console.rb:9:in `start'
    from /var/lib/gems/2.3.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /var/lib/gems/2.3.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /var/lib/gems/2.3.0/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>'
sawa
  • 165,429
  • 45
  • 277
  • 381
ggoha
  • 1,996
  • 3
  • 23
  • 31

1 Answers1

2

It's not exactly like that, but it's very similar.

You can use method method. For example

2.method(:hours)
=> #<Method: Fixnum(Numeric)#hours>

or probably more detail

2.method(:hours).source_location
=> ["~/.rvm/gems/ruby-2.3.3/gems/activesupport-4.2.7.1/lib/active_support/core_ext/numeric/time.rb", 29]

and after that you can use debuger(if posible) or go deeper

Another detail in this answer How to find where a method is defined at runtime?

ggoha
  • 1,996
  • 3
  • 23
  • 31