Project

General

Profile

Actions

Feature #710

closed

Pathname#=~

Added by quix (James M. Lawrence) about 16 years ago. Updated over 13 years ago.

Status:
Closed
Target version:
-
[ruby-core:19690]

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

pathname-match.patch (341 Bytes) pathname-match.patch quix (James M. Lawrence), 11/04/2008 03:13 PM
Actions #1

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

Actions #2

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

Actions #3

Updated by ko1 (Koichi Sasada) about 16 years ago

  • Assignee set to matz (Yukihiro Matsumoto)

=begin

=end

Actions #4

Updated by ko1 (Koichi Sasada) about 16 years ago

  • Assignee changed from matz (Yukihiro Matsumoto) to akr (Akira Tanaka)

=begin

=end

Actions #5

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0