If statement in Ruby using Regex

前端 未结 4 1217
终归单人心
终归单人心 2021-01-29 07:30

Everything seems to be working fine except the commented line:

#return false if not s[0].upcase =~ /AZ/

and the fourth check.

What is t

4条回答
  •  北海茫月
    2021-01-29 07:55

    It's easy with regex:

    def starts_with_consonant?(s)
       !!(s =~  /^[bcdfghjklmnpqrstvwxyz]/i)
    end
    

    This matches the first character of the string with the set of consonants. The !! forces the output to true/false.

提交回复
热议问题