ruby使用正则匹配字符串返回boolean
FAKE_PHONE_PATTERN = /fake_phone\d{11}/
phone = fake_phone88888888888
def fake_phone?
FAKE_PHONE_PATTERN === phone 这两种写法都可以用=== 过不了rubocop的检测。
phone =~ FAKE_PHONE_PATTERN ? true : false
end
FAKE_PHONE_PATTERN === phone 这两种写法都可以用=== 过不了rubocop的检测。
phone =~ FAKE_PHONE_PATTERN ? true : false
end
x = '10.0.0'
x =~ /\d*\.\d*\.\d*/ ? true : false # => true
# Unlike c-style languages, 0 is true in ruby:
x =~ /\d*\.\d*\.\d*/ # => 0
0 ? true : false # => true