Module: ArrayTweaks::Extension

Defined in:
lib/array-tweaks.rb

Instance Method Summary collapse

Instance Method Details

#drop_lastObject



6
7
8
# File 'lib/array-tweaks.rb', line 6

def drop_last
  slice(0, (size - 1).abs) # or slice(0...-1)
end

#drop_last!Object



10
11
12
# File 'lib/array-tweaks.rb', line 10

def drop_last!
  slice!(-1)
end

#each_after(n) ⇒ Object



19
20
21
22
23
# File 'lib/array-tweaks.rb', line 19

def each_after(n)
  each_with_index do |item, i|
    yield(item) if i >= n
  end
end

#each_with_index_and_sizeObject



14
15
16
17
# File 'lib/array-tweaks.rb', line 14

def each_with_index_and_size
  size = self.size
  each_with_index { |item, index| yield(item, index, size) }
end

#map_key(key) ⇒ Object



25
26
27
# File 'lib/array-tweaks.rb', line 25

def map_key(key)
  map { |item| item[key] }
end