This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Obj | |
attr_reader :a | |
def initialize(a) | |
@a = a | |
end | |
def ==(other) | |
a == other.a | |
end | |
alias_method :eql?, :== | |
def hash | |
a.hash | |
end | |
end | |
o1 = Obj.new(:a) | |
o2 = Obj.new(:a) | |
o3 = Obj.new(:a) | |
a = [[o1], [o2], [o3]] | |
p a.inject(:&) # Recognizes and returns the common element | |
#------------------------------------ | |
class Obj | |
attr_reader :a | |
def initialize(a) | |
@a = a | |
end | |
def ==(other) | |
a == other.a | |
end | |
end | |
o1 = Obj.new(:a) | |
o2 = Obj.new(:a) | |
o3 = Obj.new(:a) | |
a = [[o1], [o2], [o3]] | |
p a.inject(:&) # Does not recognize common elements.. returns [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment