In ruby, what is the best/most-elegant way to return a value such as:
#method returns true or false if 'do i match' is present in string
def method(str)
str =~ /do i match/
end
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.
Some people would do:
The second
!runs the truthiness test and negates the answer, then the first!negates it again to get the initial truthy result.I rather prefer the more explicit syntax:
This does the truthiness, but to me feels clearer. Do what feels cleanest to you.