Alex Froelich
2013-Aug-29 14:42 UTC
Using Match with Regexp-Do not quite understand the formula
Hi Ruby on Rails community! I am trying to write a program that uses the .match command to find out if a string contains a certain word-then using that information write a conditional statement. The issue I am running into is that I am self teaching myself and do not really know how to properly use this new found str. method. Right now this is what my code looks like def your_plans(activity) #want to use a method for this one if /activity/.match("movie") #this is where I get it wrong, I am not sure if this is the proper way to present the match, and if i am #putting the argument in the correct position. puts "I love movies too!" else puts "why didn''t you see a movie?" end end puts your_plans("Yesterday, I went to go see a movie") it is super basic, as I am just a starter. I think the rest of my code is correct, i just cant figure out the match method. If anyone has some pointers on why certain pieces go where that would be really helpful. I have been using this site to look up and learn methods. http://www.ruby-doc.org/core-1.9.3/String.html thanks! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/25db479ad61ce73b66b95dd1efd3a9b7%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
Walter Lee Davis
2013-Aug-29 14:47 UTC
Re: Using Match with Regexp-Do not quite understand the formula
On Aug 29, 2013, at 10:42 AM, Alex Froelich wrote:> Hi Ruby on Rails community! > > I am trying to write a program that uses the .match command to find out > if a string contains a certain word-then using that information write a > conditional statement. The issue I am running into is that I am self > teaching myself and do not really know how to properly use this new > found str. method. Right now this is what my code looks like > > def your_plans(activity) #want to use a method for this one > if /activity/.match("movie")Take the slashes off of activity, and this should just work. irb 1.9.3p429 :001 > "i love movies".match("movie") => #<MatchData "movie"> 1.9.3p429 :002 > "i love movies".match("walrus") => nil 1.9.3p429 :003 >> #this is where I get it wrong, I am not sure if this is the proper way > to present the match, and if i am #putting the argument in the correct > position. > puts "I love movies too!" > else > puts "why didn''t you see a movie?" > end > end > > puts your_plans("Yesterday, I went to go see a movie") > > > it is super basic, as I am just a starter. I think the rest of my code > is correct, i just cant figure out the match method. If anyone has some > pointers on why certain pieces go where that would be really helpful. I > have been using this site to look up and learn methods. > http://www.ruby-doc.org/core-1.9.3/String.htmlHope this helps, Walter> > thanks! > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/25db479ad61ce73b66b95dd1efd3a9b7%40ruby-forum.com. > For more options, visit https://groups.google.com/groups/opt_out.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/A2DE47B4-450C-408E-A3D0-4D92B7F34FAE%40wdstudio.com. For more options, visit https://groups.google.com/groups/opt_out.
Alex Froelich
2013-Aug-29 17:03 UTC
Re: Using Match with Regexp-Do not quite understand the formula
Walter Davis wrote in post #1119949:> On Aug 29, 2013, at 10:42 AM, Alex Froelich wrote: > >> Hi Ruby on Rails community! >> >> I am trying to write a program that uses the .match command to find out >> if a string contains a certain word-then using that information write a >> conditional statement. The issue I am running into is that I am self >> teaching myself and do not really know how to properly use this new >> found str. method. Right now this is what my code looks like >> >> def your_plans(activity) #want to use a method for this one >> if /activity/.match("movie") > > Take the slashes off of activity, and this should just work. > > irb > 1.9.3p429 :001 > "i love movies".match("movie") > => #<MatchData "movie"> > 1.9.3p429 :002 > "i love movies".match("walrus") > => nil > 1.9.3p429 :003 > > >> >> >> it is super basic, as I am just a starter. I think the rest of my code >> is correct, i just cant figure out the match method. If anyone has some >> pointers on why certain pieces go where that would be really helpful. I >> have been using this site to look up and learn methods. >> http://www.ruby-doc.org/core-1.9.3/String.html > > Hope this helps, > > WalterHi Walter, Thanks for your quick reply. I removed the "/" around activity, but when i put everything in my code. I am receiving a syntex error. def welcome(activity) if activity.match("movies") puts "Yes, Movies are awesome!" else puts "why don''t you like movies?" end end puts activity("I like going to movies") What i am looking to get in the output is either a "Yes, Movies are awesome" if .match finds "movies", or "why don''t you like movies?" if .match is unable to find movies in the statement. I am thinking it still has to do with me not setting up the argument and .match correctly. thanks, Alex -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0ff33398ab11529b56b1ca5acd499d55%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
Walter Lee Davis
2013-Aug-29 17:07 UTC
Re: Using Match with Regexp-Do not quite understand the formula
On Aug 29, 2013, at 1:03 PM, Alex Froelich wrote:> Walter Davis wrote in post #1119949: >> On Aug 29, 2013, at 10:42 AM, Alex Froelich wrote: >> >>> Hi Ruby on Rails community! >>> >>> I am trying to write a program that uses the .match command to find out >>> if a string contains a certain word-then using that information write a >>> conditional statement. The issue I am running into is that I am self >>> teaching myself and do not really know how to properly use this new >>> found str. method. Right now this is what my code looks like >>> >>> def your_plans(activity) #want to use a method for this one >>> if /activity/.match("movie") >> >> Take the slashes off of activity, and this should just work. >> >> irb >> 1.9.3p429 :001 > "i love movies".match("movie") >> => #<MatchData "movie"> >> 1.9.3p429 :002 > "i love movies".match("walrus") >> => nil >> 1.9.3p429 :003 > >> >>> >>> >>> it is super basic, as I am just a starter. I think the rest of my code >>> is correct, i just cant figure out the match method. If anyone has some >>> pointers on why certain pieces go where that would be really helpful. I >>> have been using this site to look up and learn methods. >>> http://www.ruby-doc.org/core-1.9.3/String.html >> >> Hope this helps, >> >> Walter > > > Hi Walter, > > Thanks for your quick reply. I removed the "/" around activity, but when > i put everything in my code. I am receiving a syntex error. > > def welcome(activity) > if activity.match("movies") > puts "Yes, Movies are awesome!" > else > puts "why don''t you like movies?" > end > end > puts activity("I like going to movies") > > What i am looking to get in the output is either a "Yes, Movies are > awesome" if .match finds "movies", or "why don''t you like movies?" if > .match is unable to find movies in the statement. I am thinking it still > has to do with me not setting up the argument and .match correctly. > > thanks, > AlexYour method is called welcome(), but you are calling activity(). Make the last line read as this: puts welcome("I like going to movies") and you will see the output you desire. Walter> > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0ff33398ab11529b56b1ca5acd499d55%40ruby-forum.com. > For more options, visit https://groups.google.com/groups/opt_out.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/009CB0CE-39A4-4C1B-BF7D-AFC55EAC5305%40wdstudio.com. For more options, visit https://groups.google.com/groups/opt_out.
Alex Froelich
2013-Aug-29 17:48 UTC
Re: Using Match with Regexp-Do not quite understand the formula
Walter Davis wrote in post #1119974:> On Aug 29, 2013, at 1:03 PM, Alex Froelich wrote: > >>>> >>> 1.9.3p429 :003 > >>> >> puts "Yes, Movies are awesome!" >> >> thanks, >> Alex > > Your method is called welcome(), but you are calling activity(). Make > the last line read as this: > > puts welcome("I like going to movies") > > and you will see the output you desire. > > WalterDo''h!! Thanks for catching that for me :) Everything is working out really nicely now. Thanks for taking the time to help me out, Walter. best, Alex -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d511de50d85e7eb1c5b531cbdaf2cdc2%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.