Compare multiple variables with a value in a single expression

I have two variables a and b . I want to compare both a and b with a value like 10 , for example.

I can do it like this:

 10 == a && 10 == b 

But I was wondering if there is a way to write this in one expression? (For example, like a == b == 10 )

+6
source share
2 answers
 [a,b,3].all? {|x| x==10} 

but in this case

 [].all? {|x| x==10} 

will also return true

+9
source

Updated after comment from aztaroth:

 [a,b].uniq == [10] 
+4
source

Source: https://habr.com/ru/post/916239/


All Articles