Issue #1961 has been updated by Narihiro Nakamura.


Hi.

I think nice idea and interesting proposal.

The following patch add Kernel#__dir__.
(from Nobuyoshi Nakada, thanks)


Index: prelude.rb
===================================================================
--- prelude.rb	(revision 24591)
+++ prelude.rb	(working copy)
@@ -24,12 +24,19 @@ class Thread
 end

-def require_relative(relative_feature)
-  c = caller.first
+def __dir__(*args)
+  c = caller(*args).first
   e = c.rindex(/:\d+:in /)
   file = $`
   if /\A\((.*)\)/ =~ file # eval, etc.
-    raise LoadError, "require_relative is called in #{$1}"
+    file = yield($1)
   end
-  absolute_feature = File.expand_path(File.join(File.dirname(file), relative_feature))
+  File.dirname(file)
+end
+
+def require_relative(relative_feature)
+  dir = __dir__(2) {|file|
+    raise LoadError, "require_relative is called in #{file}"
+  }
+  absolute_feature = File.expand_path(File.join(dir, relative_feature))
   require absolute_feature
 end

----------------------------------------
http://redmine.ruby-lang.org/issues/show/1961

----------------------------------------
http://redmine.ruby-lang.org