Tuesday, 15 March 2011

ruby on rails - I can't seem to grep to work on a plain string -



ruby on rails - I can't seem to grep to work on a plain string -

i beginner pardon me rather simple question:

when seek run next code:

c = "hey there you" newarray = c.grep("you") puts newarray

i error in st2: <main>': undefined methodgrep' "hey there you":string (nomethoderror)

however, when run code using array, works:

c = ["hey", "there", "you"] newarray = c.grep("you") puts newarray

the illustration in book learning showing illustration of grep beingness applied straight string, not sure why happening. can enlighten me?

grep enumerable method can applied arrays , hashes. "hey there you" string looking include? or match or scan

"hey there you".match 'you' "hey there you".scan 'you' # returns 2 results

ruby-on-rails ruby

No comments:

Post a Comment