If statement in Ruby using Regex

前端 未结 4 1219
终归单人心
终归单人心 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:49

    I'm also not sure what your regex is trying to achieve, so I can't suggest a fix. But for the entire method, I'd keep it simple by using the === operator and making the regex case-insensitive with the i option:

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

提交回复
热议问题