In converting some code from Ruby version 1.6.8 to 1.8, I found that the
construct:
“x” =~ “[x]”
has apparently changed behavior. In version 1.6.8, String#=~ will
convert a String argument into a Regexp. In version 1.8, apparently this is
now translated into a call to String#index. This can lead to results like:
%ruby -ve "p ‘x^x’ =~ ‘^x’"
ruby 1.6.8 (2002-12-24) [i386-freebsd4.7]
0
%ruby -ve "p ‘x^x’ =~ ‘^x’"
ruby 1.8.0 (2003-05-01) [i386-freebsd4.7]
1
Is this change intentional? It would seem that this change would affect
a lot of exsiting code in subtle, hard-to-find ways :o(
- Warren Brown
Hi,
In converting some code from Ruby version 1.6.8 to 1.8, I found that the
construct:
“x” =~ “”
has apparently changed behavior. In version 1.6.8, String#=~ will
convert a String argument into a Regexp. In version 1.8, apparently this is
now translated into a call to String#index.
Is this change intentional? It would seem that this change would affect
a lot of exsiting code in subtle, hard-to-find ways :o(
This is now under discussion in ruby-list. The behavior will be
either
- use String#index internally, with warning.
- give warning to discourage using string as an argument.
I will have warning in 1.8.0 anyway for any incompatible changes,
at least I’m trying so.
matz.
···
In message “[Q] Change in 1.8 String#=~ intentional?” on 03/05/24, “Warren Brown” wkb@airmail.net writes: