Skip to content

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

instance method

Set#each

() { (A) -> void } -> self
() -> ::Enumerator[A, self]
each {|element| ... } → self
each → enumerator

With a block given, calls the block once for each element in the set, passing the element as a parameter; returns self:

Example
sum = 0
Set[1, 2, 3].each {|i| sum += i }
sum # => 6

With no block given, returns an Enumerator.

See also #divide #empty? #disjoint? #encode_with also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0