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#collect!

() { (A) -> A } -> self
collect! {|element| ... } → self
collect! → enumerator

With a block given, calls the block with each element in self; replaces the element with the block’s return value:

Example
Set[1, :one, 'one', 1.0].collect! {|element| element.class }
# => Set[Integer, Symbol, String, Float]

With no block given, returns an Enumerator.

Related: see Methods for Converting.