[#69616] [Ruby trunk - Feature #11258] add 'x' mode character for O_EXCL — cremno@...
Issue #11258 has been updated by cremno phobia.
3 messages
2015/06/16
[#69643] [Ruby trunk - Misc #11276] [RFC] compile.c: convert to use ccan/list — normalperson@...
Issue #11276 has been updated by Eric Wong.
3 messages
2015/06/17
[#69751] [Ruby trunk - Bug #11001] 2.2.1 Segmentation fault in reserve_stack() function. — kubo@...
Issue #11001 has been updated by Takehiro Kubo.
3 messages
2015/06/27
[ruby-core:69431] [Ruby trunk - Bug #11205] [Open] Problem with __dir__ or it's description
From:
gam3-ruby@...3.net
Date:
2015-06-01 15:08:55 UTC
List:
ruby-core #69431
Issue #11205 has been reported by Allen Morris.
----------------------------------------
Bug #11205: Problem with __dir__ or it's description
https://bugs.ruby-lang.org/issues/11205
* Author: Allen Morris
* Status: Open
* Priority: Low
* Assignee:
* ruby -v:
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~
Kernel#__dir__
Returns the canonicalized absolute path of the directory of the file from which this method is called. It means symlinks in the path is resolved. If __FILE__ is nil, it returns nil. The return value equals to File.dirname(File.realpath(__FILE__)).
~~~
Here is a script that shows the problem.
~~~
def mytest(&block)
ret = block.binding.eval( '[ __FILE__, __dir__ ]' )
assert_equal("bill", __dir__)
end
dir = __dir__
eval(%q(
ret = mytest { }
ret[0] == '/bill/bill'
ret[1] == dir # where it shoudl == '/bill'
#
), nil, '/bill/bill', 1)
~~~
Even without the binding problem it is clear from the current ruby tests that
`\_\_dir__` is not equal to `File.realpath(\_\_FILE__)`.
~~~
def test___dir__
assert_instance_of String, __dir__
assert_equal(File.dirname(File.realpath(__FILE__)), __dir__)
bug8436 = '[ruby-core:55123] [Bug #8436]'
assert_equal(__dir__, eval("__dir__", binding), bug8436)
bug8662 = '[ruby-core:56099] [Bug #8662]'
assert_equal("arbitrary", eval("__dir__", binding, "arbitrary/file.rb"), bug8662)
assert_equal("arbitrary", Object.new.instance_eval("__dir__", "arbitrary/file.rb"), bug8662)
end
~~~
possible solution:
Fix `eval` so that it never affects `Kernel#__dir__` and add a `Kernel#__file__` method and rewrite the description as:
~~~
Kernel#__dir__
Returns the canonicalized absolute path of the directory of the file from which this method is called. It means symlinks in the path is resolved. The return value equals to File.dirname(File.realpath(__file__)).
~~~
And a definition for `\_\_file__`
~~~
Kernel#__file__
Returns the canonicalized absolute path of the directory of the file from which this method is called. It means symlinks in the path is resolved. The return value equals to File.dirname(File.realpath(__file__)).
Note: __file__ is equal to __FILE__ except inside of #eval and #eval_instance.
~~~
This assumes that the purpose of `\_\_dir__` is to find files in the current filesystem, and not for the purpose of debugging.
---Files--------------------------------
patch (900 Bytes)
--
https://bugs.ruby-lang.org/