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

() { (A) -> A } -> self
map!

Alias of #collect!

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.

See also #collect! #length #member? #keep_if also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0