Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ruby - moved grep from string method to enumerable
ruby-1.8.7-p352 $ irb
1.8.7 :001 > thing = 'sometext'
=> "sometext"
1.8.7 :002 > thing.grep(/some/)
=> ["sometext"]
ruby-1.9.2-p290 $ irb
1.9.2p290 :001 > thing = 'sometext'
=> "sometext"
1.9.2p290 :002 > thing.grep(/some/)
NoMethodError: undefined method `grep' for "sometext":String
from (irb):2
from /Users/michael/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
1.9.2p290 :003 > thing.lines.grep(/some/)
=> ["sometext"]
@johnenali
Copy link

johnenali commented Jul 26, 2013

thank you

Loading

@fosskers
Copy link

fosskers commented Jan 10, 2015

This has saved me just now as well.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment