Module: FatCore::Array

Included in:
Array
Defined in:
lib/fat_core/array.rb

Instance Method Summary collapse

Instance Method Details

#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.

[View source]

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

#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.

[View source]

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

#last_iObject

Return the index of the last element of this Array. This is just a convenience for an oft-needed Array attribute.

[View source]

5
6
7
# File 'lib/fat_core/array.rb', line 5

def last_i
  self.size - 1
end