Skip to content

Instantly share code, notes, and snippets.

@sshaw
Created October 26, 2014 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sshaw/d01a5cc84f46d54c0566 to your computer and use it in GitHub Desktop.
Save sshaw/d01a5cc84f46d54c0566 to your computer and use it in GitHub Desktop.
Ruby Classes With Different Equality Behavior

Ruby Classes With Different ==, eql?, and === Behavior

Float

1.0 == 1     # true
1.0.eql? 1   # false
1.0 === 1    # true

IPAddr

require "ipaddr"

ip = IPAddr.new "127.0.0.1"
ip == "127.0.0.1"   # true
ip.eql? "127.0.0.1" # false
ip === "127.0.0.1"  # true

CSV::Row

require "csv"

row = {"A"=>"X", "B"=>"Y"}
csv = CSV::Row.new row.keys, row.values

csv == row.to_a   # true
csv.eql? row.to_a # false
csv === row.to_a  # true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment