From: Robert Klemme Date: 2005-12-06T23:47:34+09:00 Subject: Re: How can I find __LINE__ on the execution stack ? Christer Nilsson wrote: > I would like to be able to display the line number in my simple > assert. > > 1 def assert(expect, actual, *msg) > 2 expect==actual ? print(".") : print("\nAssert at line #{__LINE__} > failed: #{expect.inspect} <> #{actual.inspect} #{msg}\n") > 3 end > 4 > 5 assert 1, 2 > 6 assert 1, 1 > > The solution above erroneously displays line 2 instead of line 5. You can use caller[0] to get the info you want: irb(main):007:0> def test irb(main):008:1> p caller[0] irb(main):009:1> end => nil irb(main):010:0> test "(irb):10:in `irb_binding'" => nil Kind regards robert