Sha256: 1c4982a88278d17e32db03177d1623fb0bc5dbc33803e52b378019e183c6c50e

Contents?: true

Size: 596 Bytes

Versions: 4

Compression:

Stored size: 596 Bytes

Contents

class Hash
  # A "smarter" hash#each which iterates through each
  # _value_ if only one block parameter is given.
  #
  #   require 'facet/hash/each'
  #
  #   {:a=>"a", 2=>"b", "x"=>"c"}.each{ |v| puts v }
  #
  # _produces_
  #
  #   a
  #   b
  #   c
  #
  # WARNING! Use with caution. Methods from other libraries 
  # may depend on the old behavior, expecting a two element 
  # array to be passed into a single block argument.
  def each(&yld)
    case yld.arity
    when 0
    when 1
      each_value{|v| yield(v)}
    else
      each_pair{|k,v| yld.call(k,v)}
    end
    self
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
facets-0.6.3 lib/facet/hash/each.rb
facets-0.7.0 lib/facet/hash/each.rb
facets-0.7.1 lib/facet/hash/each.rb
facets-0.7.2 lib/facet/hash/each.rb