ITP - more stuff - exercise - boolean_regex.rb

irb :001 > "powerball" =~ /b/
=> 5

The expression returned a 5. This means that the first match that took
place was at the fifth index of the string. Remember indices start
counting from zero. Since 5 is a truthy value (i.e., in Ruby, 5
evaluates to true), we can use it as a boolean to check for matches.

def has_a_b?(string)
  if string =~ /b/
    puts "We have a match!"
  else
    puts "No match here."
  end
end

has_a_b?("basketball")
has_a_b?("football")
has_a_b?("hockey")
has_a_b?("golf")

This works! The print out is...

We have a match
We have a match
No match here.
No match here.