Over a million developers have joined DZone.

How to check multiple variables for equality in #ruby the simple way

·

 

class Array
	def same?
		uniq.length==1
	end
end

x = 1
y = 2
z = 2
l = 2

# old way : x==y and y==z
puts [x,y,z].same? # false
# old way : y==z and z==l
puts [y,z,l].same? # true
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}