syntax - Simple way to test if multiple variables have same value, ruby -
is there simple way of testing several variables have same value in ruby?
something linke this:
if == b == c == d #does not work #do because a, b, c , d have same value end
of course possible check each variable against master see if true, bit more syntax , not clear.
if == b && == c && == d #does work #we have tested same thing, more syntax. end
another reason why need if work on each variable before test.
if array1.sort == array2.sort == array3.sort == array4.sort #does not work #this clear , not introduce unnecessary variables end #vs tempclutter = array1.sort if tempclutter == array2.sort && tempclutter == array3.sort && tempclutter == array4.sort #works #this works, introduces temporary variables makes code more unclear end
throw them array , see if there 1 unique item.
if [a,b,c,d].uniq.length == 1 #i solve every problem putting things arrays end
as sawa points out in comments .one? fails if false or nil.
Comments
Post a Comment