Skip to content

Instantly share code, notes, and snippets.

@miketheman
Created January 27, 2012 18:52
Show Gist options
  • Select an option

  • Save miketheman/1690297 to your computer and use it in GitHub Desktop.

Select an option

Save miketheman/1690297 to your computer and use it in GitHub Desktop.
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
Copy Markdown

thank you

@fosskers

Copy link
Copy Markdown

This has saved me just now as well.

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