public
Created

Array#uniq in Ruby 1.8.7

  • Download Gist
output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
~~ [EqualA, EqualB].uniq ~~
EqualA: hash
EqualB: hash
[EqualA, EqualB]
 
~~ [EqualA, EqualB, EqualC].uniq ~~
EqualA: hash
EqualB: hash
EqualC: hash
[EqualA, EqualB, EqualC]
 
 
~~ [EqualHashA, EqualHashB].uniq ~~
EqualHashA: hash
EqualHashB: hash
EqualHashB: eql? against EqualHashA
[EqualHashA, EqualHashB]
 
~~ [EqualHashA, EqualHashB, EqualHashC].uniq ~~
EqualHashA: hash
EqualHashB: hash
EqualHashB: eql? against EqualHashA
EqualHashC: hash
EqualHashC: eql? against EqualHashB
EqualHashC: eql? against EqualHashA
[EqualHashA, EqualHashB, EqualHashC]
 
 
~~ [EqualHashAndEqlA, EqualHashAndEqlB].uniq ~~
EqualHashAndEqlA: hash
EqualHashAndEqlB: hash
EqualHashAndEqlB: eql? against EqualHashAndEqlA
EqualHashAndEqlA: hash
EqualHashAndEqlB: hash
[EqualHashAndEqlA]
 
~~ [EqualHashAndEqlA, EqualHashAndEqlB, EqualHashAndEqlC].uniq ~~
EqualHashAndEqlA: hash
EqualHashAndEqlB: hash
EqualHashAndEqlB: eql? against EqualHashAndEqlA
EqualHashAndEqlC: hash
EqualHashAndEqlC: eql? against EqualHashAndEqlA
EqualHashAndEqlA: hash
EqualHashAndEqlB: hash
EqualHashAndEqlC: hash
[EqualHashAndEqlA]
 
~~ [EqualHashAndEqlA, EqualHashAndEqlB, EqualHashAndEqlC, EqualHashAndEqlD].uniq ~~
EqualHashAndEqlA: hash
EqualHashAndEqlB: hash
EqualHashAndEqlB: eql? against EqualHashAndEqlA
EqualHashAndEqlC: hash
EqualHashAndEqlC: eql? against EqualHashAndEqlA
EqualHashAndEqlD: hash
EqualHashAndEqlD: eql? against EqualHashAndEqlA
EqualHashAndEqlA: hash
EqualHashAndEqlB: hash
EqualHashAndEqlC: hash
EqualHashAndEqlD: hash
[EqualHashAndEqlA]
ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
class Equal
attr_accessor :name
 
def initialize(name)
@name = name
end
 
def inspect
@name
end
 
def hash
puts "#{name}: hash"
super
end
 
def eql?(co)
puts "#{name}: eql? against #{co.name}"
super
end
 
def ==(co)
puts "#{name}: == against #{co.name}"
super
end
end
 
EqualA = Equal.new('EqualA')
EqualB = Equal.new('EqualB')
EqualC = Equal.new('EqualC')
 
puts
 
def run(cmd)
puts "~~ #{cmd} ~~"
puts eval(cmd).inspect
puts
end
 
run '[EqualA, EqualB].uniq'
run '[EqualA, EqualB, EqualC].uniq'
 
class EqualHash < Equal
def hash
puts "#{name}: hash"
1000
end
end
 
EqualHashA = EqualHash.new('EqualHashA')
EqualHashB = EqualHash.new('EqualHashB')
EqualHashC = EqualHash.new('EqualHashC')
 
puts
 
run '[EqualHashA, EqualHashB].uniq'
run '[EqualHashA, EqualHashB, EqualHashC].uniq'
 
class EqualHashAndEql < EqualHash
def eql?(co)
puts "#{name}: eql? against #{co.name}"
true
end
end
 
EqualHashAndEqlA = EqualHashAndEql.new('EqualHashAndEqlA')
EqualHashAndEqlB = EqualHashAndEql.new('EqualHashAndEqlB')
EqualHashAndEqlC = EqualHashAndEql.new('EqualHashAndEqlC')
EqualHashAndEqlD = EqualHashAndEql.new('EqualHashAndEqlD')
 
puts
 
run '[EqualHashAndEqlA, EqualHashAndEqlB].uniq'
run '[EqualHashAndEqlA, EqualHashAndEqlB, EqualHashAndEqlC].uniq'
run '[EqualHashAndEqlA, EqualHashAndEqlB, EqualHashAndEqlC, EqualHashAndEqlD].uniq'

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.