Issue #710 has been updated by James M. Lawrence.


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.

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

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