Module: FatCore::Array
- Included in:
- Array
- Defined in:
- lib/fat_core/array.rb
Instance Method Summary collapse
-
#difference(other) ⇒ Object
Return an Array that is the difference between this Array and +other+, but without removing duplicates as the Array#- method does.
-
#intersect(other) ⇒ Object
Return a new Array that is the intersection of this Array with +other+, but without removing duplicates as the Array#& method does.
-
#last_i ⇒ Object
Return the index of the last element of this Array.
Instance Method Details
permalink #difference(other) ⇒ Object
Return an Array that is the difference between this Array and +other+, but without removing duplicates as the Array#- method does. All items of this Array are included in the result unless they also appear in the +other+ Array.
25 26 27 28 29 30 31 |
# File 'lib/fat_core/array.rb', line 25 def difference(other) result = [] each do |itm| result << itm unless other.include?(itm) end result end |
permalink #intersect(other) ⇒ Object
Return a new Array that is the intersection of this Array with +other+, but without removing duplicates as the Array#& method does. All items of this Array are included in the result but only if they also appear in the +other+ Array.
13 14 15 16 17 18 19 |
# File 'lib/fat_core/array.rb', line 13 def intersect(other) result = [] each do |itm| result << itm if other.include?(itm) end result end |
permalink #last_i ⇒ Object
Return the index of the last element of this Array. This is just a convenience for an oft-needed Array attribute.
5 6 7 |
# File 'lib/fat_core/array.rb', line 5 def last_i self.size - 1 end |