I wonder why ruby give and, or less precedence than &&, || , and assign operator? Is there any reason?
I wonder why ruby give and , or less precedence than && , ||
Share
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.
My guess is that’s a direct carry-over from Perl. The operators
orandandwere added later in Perl 5 for specific situations were lower precedence was desired.For example, in Perl, here we wish that
||had lower precedence, so that we could write:and be sure that the
||was not going to gobble up part of the action. Perl 5 introducedor, a new version of||that has low precedence, for exactly this purpose.An example in Ruby where you could use
orbut not||:If you used
||, it would be a syntax error.