
Submitted by transami (Sat Jul 30 21:54:29 UTC 2005)
irb(main):001:0> __DIR__ = File.dirname(__FILE__)
=> "."
irb(main):002:0> def x
irb(main):003:1> p __DIR__
irb(main):004:1> end
=> nil
irb(main):005:0> x
NameError: undefined local variable or method `__DIR__' for main:Object
from (irb):3:in `x'
from (irb):5
But again built-in would be even better.

| Comments | Current voting | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|


RCRchive copyright © David Alan Black, 2003-2005.
Powered by .
You could define it as a method:
module Kernel def __DIR__ File.dirname(__FILE__) end endDavid Black
Ah, Kernel method. Of course. Thanks. Had constant stuck in my mind for some reason.
T.
I should point out for those who don;t see it right off, that this is still a viable addition despite it being definable as a kernel method. Notice that the kernel method will always return the directory location of the file it is defined in, not the one you call it from. So it doesn't really work.
module KernelendHey, thanks! That went right into Facets. If you would like I can credit you in the source code, whomever you are?
T. (Trans)