私が呼び出すときArray#-
、それは私が比較している文字列の比較メソッドを呼び出さないようです:
class String
def <=>(v)
puts "#{self} <=> #{v}"
super(v)
end
def ==(v)
puts "#{self} == #{v}"
super(v)
end
def =~(v)
puts "#{self} =~ #{v}"
super(v)
end
def ===(v)
puts "#{self} == #{v}"
super(v)
end
def eql?(v)
puts "#{self}.eql? #{v}"
super(v)
end
def equal?(v)
puts "#{self}.equal? #{v}"
super(v)
end
def hash()
puts "#{self}.hash"
super
end
end
p %w{one two three} - %w{two}
それはただ戻ります:
["one", "three"]
それで、何をしているのArray#-
ですか?
また、Ruby1.9.2p290を使用しています。1.8.7では、無限ループが発生するようです。