regexp warning in String.split?

C

Chris Morris

irb(main):001:0> 'a,b'.split(',')
=> ["a", "b"]
irb(main):004:0> 'a => b'.split(' => ')
(irb):4: warning: string pattern instead of regexp; metacharacters
no longer eff
ective
=> ["a", "b"]

Why do I get a warning on the second split call?
 
B

Brian Candler

irb(main):001:0> 'a,b'.split(',')
=> ["a", "b"]
irb(main):004:0> 'a => b'.split(' => ')
(irb):4: warning: string pattern instead of regexp; metacharacters
no longer eff
ective
=> ["a", "b"]

Why do I get a warning on the second split call?

Because you should be using:

'a => b'.split(/ => /)

(I don't think '=' or '>' by themselves has significance in a regexp, but in
combination they might do - if you use odd things like assertions)

Cheers,

Brian.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top