string !~ string, not possible in cvshead

  • Thread starter Simon Strandgaard
  • Start date
S

Simon Strandgaard

While upgrading and reinstalling misc modules I regulary use, I bumped
into this construction. I don't know if the recent switch from GNU to
Oniguruma has broken anything ?

Any reason that String isn't allowed anymore ?


server> ruby a.rb
a.rb:1:in `=~': type mismatch: String given (TypeError)
from a.rb:1
server> expand -t2 a.rb
if "hello" !~ "l{2}"
raise
end
server>


Changing right argument into a regexp makes it work.

server> ruby a.rb
server> expand -t2 a.rb
if "hello" !~ /l{2}/
raise
end
server> ruby -v
ruby 1.9.0 (2004-03-31) [i386-freebsd5.1]
server>

Perhaps change exception message to something else, for instance:
in `!~': right argument must be Regexp, but was String (TypeError)

That would be less confusing ;-)
 
G

Gennady Bystritsky

While upgrading and reinstalling misc modules I regulary use, I bumped
into this construction. I don't know if the recent switch from GNU to
Oniguruma has broken anything ?

Any reason that String isn't allowed anymore ?

This behavior was kind of "promised" starting from 1.8:

[mac.gfbm:51]bystr> irb
irb(main):001:0> "aaa" !~ "bbb"
(irb):1: warning: string =~ string will be obsolete; use explicit regexp
=> true
irb(main):002:0>
[mac.gfbm:52]bystr> ruby -v
ruby 1.8.1 (2003-12-25) [powerpc-darwin]

server> ruby a.rb
a.rb:1:in `=~': type mismatch: String given (TypeError)
from a.rb:1
server> expand -t2 a.rb
if "hello" !~ "l{2}"
raise
end
server>


Changing right argument into a regexp makes it work.

server> ruby a.rb
server> expand -t2 a.rb
if "hello" !~ /l{2}/
raise
end
server> ruby -v
ruby 1.9.0 (2004-03-31) [i386-freebsd5.1]
server>

Perhaps change exception message to something else, for instance:
in `!~': right argument must be Regexp, but was String (TypeError)

That would be less confusing ;-)

Sincerely,
Gennady Bystritsky
 
S

Simon Strandgaard

While upgrading and reinstalling misc modules I regulary use, I bumped
into this construction. I don't know if the recent switch from GNU to
Oniguruma has broken anything ?

Any reason that String isn't allowed anymore ?

This behavior was kind of "promised" starting from 1.8:

[mac.gfbm:51]bystr> irb
irb(main):001:0> "aaa" !~ "bbb"
(irb):1: warning: string =~ string will be obsolete; use explicit regexp
=> true
irb(main):002:0>
[mac.gfbm:52]bystr> ruby -v
ruby 1.8.1 (2003-12-25) [powerpc-darwin]

Thanks for the answer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top