Sha256: 4f9a604c445c5297e79bb92835f58b035c2f3eb8720e5136cd85114d8ed65f0a

Contents?: true

Size: 303 Bytes

Versions: 2

Compression:

Stored size: 303 Bytes

Contents

module Enumerable
  
  # Converts an enumerable into a hash, by accepting an initial value
  # or a block to compute the value for a given key.
  def convert_to_hash(init_val = nil)
    hash = {}
    self.each do |key|
      hash[key] = block_given? ? yield(key) : init_val
    end
    hash
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
iron-extensions-1.1.3 lib/iron/extensions/enumerable.rb
iron-extensions-1.1.2 lib/iron/extensions/enumerable.rb