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

Struct#each

each {|value| ... } → self
each → enumerator

Calls the given block with the value of each member; returns self:

Example
Customer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
joe.each {|value| p value }

Output:

Example
"Joe Smith"
"123 Maple, Anytown NC"
12345

Returns an Enumerator if no block is given.

Related: each_pair.

See also #dig #each_pair #deconstruct_keys #eql? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0