I’m currently learning Ruby and I can’t seem to wrap around what if /start/../end does… Help?
while gets
print if /start/../end/
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.
Since you mentioned that you’re new to Ruby, it’s first worth taking note that you’re dealing with Regular Expressions (regex) in the example – anything that is delimited between two forward slashes:
Regular Expressions are a powerful way of matching a certain combination of letters from a larger string.
The double dot notation is the flip-flop operator, a controversial construct probably inherited from Perl and not usually recommended to be used because it can lead to confusion.
It means the following:
It will collectively evaluate to false until the left hand operand is true. At which point it will collectively evaluate to true. However it will only remain true until the right hand operand evaluates to true – at which point it will again evaluate collectively to false.
Using your above example therefore: