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!
set.c
View on GitHub ↗
static VALUE
set_i_collect(VALUE set)
{
RETURN_SIZED_ENUMERATOR(set, 0, 0, set_enum_size);
rb_check_frozen(set);
VALUE new_set = set_s_alloc(rb_obj_class(set));
if (RSET_COMPARE_BY_IDENTITY(set)) {
set_i_compare_by_identity(new_set);
}
set_iter(set, set_collect_i, (st_data_t)new_set);
set_i_initialize_copy(set, new_set);
return set;
}
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.