新手求教!!!! 如题:ruby 数组的 减法是通过什么判断两个对象是否相等的?自己的类想支持数组减法应该实现哪些方法?
puts "诶呦,这个发帖好高科技啊!!!!"
我以为他会执行代码呢·····
It compares elements using their hash and eql? methods for efficiency.
http://ruby-doc.org/core-2.3.1/Array.html#method-i-2D
谢了!!
对象其实就是一个内存地址吧,内存地址相等就是相等了。
[84] pry(main)> show-doc Array#- From: array.c (C Method): Owner: Array Visibility: public Signature: -(arg1) Number of lines: 11 Array Difference Returns a new array that is a copy of the original array, removing any items that also appear in other_ary. The order is preserved from the original array. It compares elements using their #hash and #eql? methods for efficiency. [ 1, 1, 2, 2, 3, 3, 4, 5 ] - [ 1, 2, 4 ] #=> [ 3, 3, 5 ] If you need set-like behavior, see the library class Set.