Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

DZone's Guide to

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

·
Free Resource

 

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:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}