From: Ruby Newbee Date: 2009-11-28T12:49:36+09:00 Subject: Re: where is grep? Thanks, that sounds be more reasonable, b/c I like to grep from an array not a string (yes perl does this). btw, why 0/0 got failed but 0.0/0.0 seems valid? irb(main):144:0> v=0/0 ZeroDivisionError: divided by 0 from (irb):144:in `/' from (irb):144 from /usr/bin/irb:12:in `
' irb(main):145:0> v=0.0/0.0 => NaN 2009/11/28 Florian Gilcher : > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Grep is not defined on Ruby 1.9-Strings. > > It was on Ruby 1.8-Strings, but only because they were belonging to the > group of objects that mixed in Enumerable. > > There, grep behaves like this (line by line): > >  x = "hello world baby girl" >  x.grep(/hello/) >  #=> ["hello world baby girl"] >  x = "hello\nworld\nbaby\ngirl" >  x.grep(/hello/) >  #=> ["hello\n"] > > The same can be done in Ruby 1.9 by just splitting the String beforehand. > Arrays are Enumerable and thus > still have grep: > >  x = "hello\nworld\nbaby\ngirl" >  x.split("\n").grep(/hello/) >  #=> ["hello"] >