What can I use instead of (.grep)?

Hi,

I am new to ruby and to programming in general.
I am learning from an outdated book and just realized that the .grip
method can no longer be used on strings since ruby 1.9.

My question is could you please recommend an alternative method that I
could use instead of grep and works on strings?

Sincerely,

Lorant

Old:
string.grep(/re/)

New:
string =~ /re/

On Apr 19, 2012, at 3:00 PM, Loren wrote:

Hi,

I am new to ruby and to programming in general.
I am learning from an outdated book and just realized that the .grip
method can no longer be used on strings since ruby 1.9.

My question is could you please recommend an alternative method that I
could use instead of grep and works on strings?


not sure that there was a ‘grep’ in any version of ruby but .include?
tends to be useful

irb(main):001:0> test = “check”
=> “check”
irb(main):002:0> string = “This is a string with a bunch of words which
I can use to check”
=> “This is a string with a bunch of words which I can use to check”
irb(main):003:0> string.include?(test)
=> true
irb(main):004:0> test = “failure”
=> “failure”
irb(main):005:0> string.include?(test)
=> false

Craig