Sha256: c188ba72aa9c0f4f42279105a1bf29f5fc4f5e0161efcbc31e32f9886ea62d34

Contents?: true

Size: 553 Bytes

Versions: 2

Compression:

Stored size: 553 Bytes

Contents

# encoding: UTF-8
# frozen_string_literal: true

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

    def drop_last!
      slice!(-1)
    end

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

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

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

Array.include ArrayTweaks::Extension

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
array-tweaks-1.0.2 lib/array-tweaks.rb
array-tweaks-1.0.1 lib/array-tweaks.rb