Can you check if multiple values are the same on the same line in ruby on rails?

ruby, ruby-on-rails

Solution

Try this:

if [val1, val2, val3, val4, val5, val6].uniq.count == 1
  #...
end

If you wanna get fancy, you can try this

unless [val2, val3, val4, val5, val6].find{ |x| x != val1 }
  # ...
end

The above will stop as soon as it finds an element that is not equal to `val1`, otherwise, the block will be executed.

Problem

Basically, I am trying to check if 6 of my values are the same. I tried stringing them: ``` if val1 == val2 == val3 == val4 == val5 == val6 #... end ``` But this errors out. Is this possible using another method? Thanks

Original source