Method: Hash#each

Defined in:
ext/enterprise_script_service/mruby/mrblib/hash.rb

#each(&block) ⇒ Object Also known as: each_pair

Calls the given block for each element of self and pass the key and value of each element.

call-seq:

hsh.each      {| key, value | block } -> hsh
hsh.each_pair {| key, value | block } -> hsh
hsh.each                              -> an_enumerator
hsh.each_pair                         -> an_enumerator

If no block is given, an enumerator is returned instead.

h = { "a" => 100, "b" => 200 }
h.each {|key, value| puts "#{key} is #{value}" }

produces:

a is 100 b is 200

ISO 15.2.13.4.9



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'ext/enterprise_script_service/mruby/mrblib/hash.rb', line 81

def each(&block)
  return to_enum :each unless block

  keys = self.keys
  vals = self.values
  len = self.size
  i = 0
  while i < len
    block.call [keys[i], vals[i]]
    i += 1
  end
  self
end