Hi, rubyists.
I have been out of it for a bit and have just started plating with 1.8.0.
I notice a new warning around =~
“warning: string =~ string will be obsolete; use explicit regexp”
Can someone please tell me the easy way to redo the following?
arr.each { |item|
if item =~ /blah/
info = item.split(/:/)
@store [key] = "#{val}:#{info[1].strip}:"
end
}
TIA,
···
–
-mark.
Mark Probert probertm@NOSPAM_nortelnetworks.com
Nortel Networks ph. (613) 768-1082
All opinions expressed are my own and do not
reflect in any way those of Nortel Networks.
HAL_9000
(HAL 9000)
11 August 2003 18:29
2
Hi, rubyists.
I have been out of it for a bit and have just started plating with 1.8.0.
I notice a new warning around =~
“warning: string =~ string will be obsolete; use explicit regexp”
Can someone please tell me the easy way to redo the following?
arr.each { |item|
if item =~ /blah/
info = item.split(/:/)
@store [key] = “#{val}:#{info[1].strip}:”
end
}
No need to redo that one… the item on the
right of =~ is a regex, not a string.
Hal
···
----- Original Message -----
From: “Mark Probert” <probertm@NOSPAM_acm.org.web-hosting.com>
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, August 11, 2003 1:19 PM
Subject: ruby 1.8.0 and =~
This code works fine in 1.8.0.
What gives the waring is:
arr.each { |item|
if item =~ "blah" # see string on rhs of String#=~
info = item.split(/:/)
@store[key] = "#{val}:#{info[1].strip}:"
end
}
Just make sure you use a Regexp on the right side of a =~.
···
On Aug 12, Mark Probert wrote:
arr.each { |item|
if item =~ /blah/
info = item.split(/:/)
@store [key] = “#{val}:#{info[1].strip}:”
end
}
“Hal E. Fulton” hal9000@hypermetrics.com did say …
Can someone please tell me the easy way to redo the following?
arr.each { |item|
if item =~ /blah/
info = item.split(/:/)
@store [key] = “#{val}:#{info[1].strip}:”
end
}
No need to redo that one… the item on the
right of =~ is a regex, not a string.
Doh!
-laugh-
I tried to use String.scan (it takes a regex) and happened to stumble
over the answer.
Thanks for the help!
···
–
-mark.
Mark Probert probertm@NOSPAM_nortelnetworks.com
Nortel Networks ph. (613) 768-1082
All opinions expressed are my own and do not
reflect in any way those of Nortel Networks.
Saluton!
Brett H. Williams; 2003-08-11, 20:28 UTC:
Just make sure you use a Regexp on the right side of a =~.
Note that you only have to make sure that you have one instance of
Regexp and one instance of String. No need to have the Regexp on the
right side. Here’s the warning:
ruby -e ‘p “a” =~ “ab”’
-e:1: warning: string =~ string will be obsolete; use explicit regexp
nil
And here is the reason for that warning and an illustration that you
can have String/Regexp on either side of ‘=~’
ruby -e ‘p /a/ =~ “ab”’
0
ruby -e ‘p “a” =~ /ab/’
nil
Gis,
Josef ‘Jupp’ Schugt
···
–
N’attribuez jamais à la malice ce que l’incompétence explique !
– Napoléon