Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Hash#each_value

hash.each_value {|value| ... } → self
hash.each_value → new_enumerator

Calls the given block with each value; returns self:

Example
h = {foo: 0, bar: 1, baz: 2}
h.each_value {|value| puts value } # => {:foo=>0, :bar=>1, :baz=>2}

Output:

Example
0
1
2

Returns a new Enumerator if no block given:

Example
h = {foo: 0, bar: 1, baz: 2}
e = h.each_value # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:each_value>
h1 = e.each {|value| puts value }
h1 # => {:foo=>0, :bar=>1, :baz=>2}

Output:

Example
0
1
2
See also #each_pair #empty? #each_key #eql? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0