Feature #710
closedPathname#=~
Description
=begin
% ruby -r pathname -e 'p Pathname("foo") =~ /o/'
nil
% ruby -r ./lib/pathname.patched.rb -e 'p Pathname("foo") =~ /o/'
1
=end
Files
Updated by nobu (Nobuyoshi Nakada) about 16 years ago
=begin
Hi,
At Tue, 4 Nov 2008 15:12:31 +0900,
James M. Lawrence wrote in [ruby-core:19690]:
% ruby -r pathname -e 'p Pathname("foo") =~ /o/'
nil% ruby -r ./lib/pathname.patched.rb -e 'p Pathname("foo") =~ /o/'
1
In Ruby, Regexp#=~ would be used more preferably than
String#=~, I guess.
$ ruby -r pathname -e 'p /o/ =~ Pathname("foo")'
1
--
Nobu Nakada
=end
Updated by quix (James M. Lawrence) about 16 years ago
=begin
Nobuyoshi Nakada wrote:
In Ruby, Regexp#=~ would be used more preferably than
String#=~, I guess.$ ruby -r pathname -e 'p /o/ =~ Pathname("foo")'
1
However I often convert existing code from path Strings to Pathname.
I made this feature request after chasing the following bug on three
separate occasions:
def munge(file)
if file =~ %r!\d+!
# ...
end
end
'file' was a String but is now a Pathname. If NoMethodError were
raised there would be no problem. However it now calls Kernel#=~
which always returns false.
While String and Pathname are quite different, the effect of, say, '+'
is obvious in contrast to the silent failure of a regexp match.
The use of Pathname should probably be encouraged, but if it causes
too much breakage (and with no exceptions raised indicating the
problem), I can imagine people not bothering with Pathname. Making
this common case work will help the transition.
Since I regard Pathname as an "almost String", I think Pathname#=~ is
appropriate.
=end
Updated by ko1 (Koichi Sasada) about 16 years ago
- Assignee set to matz (Yukihiro Matsumoto)
=begin
=end
Updated by ko1 (Koichi Sasada) about 16 years ago
- Assignee changed from matz (Yukihiro Matsumoto) to akr (Akira Tanaka)
=begin
=end
Updated by akr (Akira Tanaka) about 16 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
=begin
Applied in changeset r20629.
=end