debugging the call stack using puts and caller in ruby


# call this anywhere inside a method
# it will print out the call stack for the current execution
# play with the numbers to narrow down the area of interest

def print_call_stack(method_name, from, to)
  from.upto(to) { |i| p "#{method_name}[#{i}]: #{caller[i]}" }
end


Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>