Home > Back-end >  How to change this ruby match line to return true or false
How to change this ruby match line to return true or false

Time:11-09

Ok so my ruby is rusty. I have a line that looks for a match...

self.volunteer_event.description.match(/^Roster #/)

gives me this...

[1] pry(#<VolunteerShift>)> self.volunteer_event.description.match(/^Roster #/)
=> #<MatchData "Roster #">

I want to change it to give me "true" if it has a match or "false" for no

What simple ruby incantation can I use to achieve this?

CodePudding user response:

Looking at the Regexp docs, I see match? and match. Use match? which returns a boolean. Functions that return a boolean often end with ? in Ruby.

  • Related