Here are two tests:
if [1,2,3,4].include? 2 && nil.nil? puts :hello end
and
if [1,2,3,4].include?(2) && nil.nil? puts :hello end
It is said above that && has a higher priority than the arguments of the method, so is it logical and 2 && nil.nil? , which is true, and passes it as an argument to include ?.
However, there is such a test:
if [1,2,3,4].include? 2 and nil.nil? puts :hello end
So, this tells me that the method arguments and " and " have the same priority (or the method arguments are higher than the " and ") since it passed 2 to be included? before processing "and".
Note. I understand that && and and have a different priority. The question is not this, but with respect to and or or against the arguments of the ruby ββmethod.
I can not find documentation to confirm this. For instances, this does not mention the method arguments at all: http://phrogz.net/programmingruby/language.html#table_18.4 or http://romhack.wikia.com/wiki/Ruby_operators .
Can anyone explain this behavior? Namely, how is it known that Ruby passes values ββas arguments to a method or process operators?
ruby operator-precedence
jshort
source share