[MacRuby-devel] Kernel#caller doesn't show directories

Brian Marick marick at exampler.com
Mon May 3 09:27:27 PDT 2010


Suppose you have foo.rb:

  def __DIR__
    caller[0]
    raise 'death'
  end

  puts __DIR__

 
If you call that from, say, a directory two levels below it, you get this:

818 $ macruby ../../foo.rb
foo.rb:2:in `__DIR__': death (RuntimeError)
	from foo.rb:6:in `<main>'

In 1.8.6 (and I sure hope in stock 1.9), you get filenames with the relative directory:

819 $ ruby ../../foo.rb
../../foo.rb:3:in `__DIR__': death (RuntimeError)
	from ../../foo.rb:6

I think that's important because there are tools (IDEs, my emacs hacks) that use the backtrace from a test to jump to the failing code. You can't do that unless you have the full pathname.

I will file a ticket if this is a real bug.


-----
Brian Marick, independent consultant
Mostly on agile methods with a testing slant
Author of /Programming Cocoa with Ruby/
www.exampler.com, www.exampler.com/blog, www.twitter.com/marick



More information about the MacRuby-devel mailing list