Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare multiple variables with a value in a single expression

Tags:

variables

ruby

I have two variables a and b. I want to compare both a and b to a value, say 10.

I can do it like this:

10 == a && 10 == b

But, I was wondering if there is any way to write it in a single expression? (E.g. like a == b == 10)

like image 502
Sayuj Avatar asked May 21 '12 09:05

Sayuj


1 Answers

[a,b,3].all? {|x| x==10}

but in this case

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

will also return true

like image 98
kp666 Avatar answered Sep 20 '22 10:09

kp666