something like this:
a = 6
case a
when /\d/ then "it's a number"
end
no luck, it doesn’t work
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When used with a value on the initializer, all case does is try it with === against each expression. The problem isn’t with case, try:
All that to say, regexes match against strings only. Try replacing the second line by:
EDIT: To answer the OP’s follow-up in comments, there’s a subtlety here.
Perhaps unexpectedly to the beginner, String#=== and Regexp#=== have different effects. So, for:
This will call
String === 'foo', not'foo' === String, etc.