Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Struct#each

() -> ::Enumerator[E, self]
() { (E value) -> void } -> self
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.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0