Sha256: 1492c521ab5a7c4e21dc114618719c664531375c430df458abc06df5e95c768a

Contents?: true

Size: 418 Bytes

Versions: 2

Compression:

Stored size: 418 Bytes

Contents

require 'darthjee/core_ext/array/hash_builder'

class Array
  def chain_map(*methods)
    result = self
    result = result.map(&(methods.shift)) until methods.empty?

    return result unless block_given?
    result.map { |*args| yield(*args) }
  end

  def as_hash(keys)
    Array::HashBuilder.new(self, keys).build
  end

  def random
    self[rand(size)]
  end

  def random!
    self.slice!(rand(size))
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
darthjee-core_ext-1.4.1 lib/darthjee/core_ext/array.rb
darthjee-core_ext-1.4.0 lib/darthjee/core_ext/array.rb