class Set::Builder[T]
include Enumerable[T]
A mutable set, for building a Set in place.
It keeps insertion order as Set does. It is not Shareable.
#to_set (and #freeze) hands the members over as a Set without
copying and leaves the builder empty, as Array::Builder#to_a does;
#to_a copies.
seen = Set::Builder[String].new
seen.add?("a") # => true
seen.add?("a") # => false
seen << "b"
seen.to_set # => Set["a", "b"]
seen.empty? # => true
<prelude>:4893
Class methods
def self.new -> Set::Builder[T]
An empty builder, as Set::Builder[Int].new.
<prelude>:4898
Methods
def add?(value: T) -> Bool
Adds value and returns whether it was new. Unlike Set#add?, the
result is a Bool.
<prelude>:4901
def merge(items: Array[T]) -> Self
Adds the elements of items, in their order, and returns the builder.
<prelude>:4903
def merge(other: Set[T]) -> Self
Adds the members of other, in their order, and returns the builder.
<prelude>:4905
def subtract(items: Array[T]) -> Self
Removes the elements of items and returns the builder.
<prelude>:4907
def subtract(other: Set[T]) -> Self
Removes the members of other and returns the builder.
<prelude>:4909
def clear -> Self
Removes every member and returns the builder.
<prelude>:4911
def replace(other: Set[T]) -> Self
Replaces the members by those of other and returns the builder.
<prelude>:4913
def select!(&: (T) -> Object) -> Self
Keeps only the members the block is truthy for and returns the builder
(even when nothing changed, unlike Ruby's nil).
<prelude>:4916
def reject!(&: (T) -> Object) -> Self
Removes the members the block is truthy for and returns the builder
(even when nothing changed, unlike Ruby's nil).
<prelude>:4919
def delete_if(&: (T) -> Object) -> Self
Removes the members the block is truthy for and returns the builder: the
same as #reject!.
<prelude>:4922
def keep_if(&: (T) -> Object) -> Self
Keeps only the members the block is truthy for and returns the builder:
the same as #select!.
<prelude>:4925
def length -> Int
The number of members: the same as #size.
<prelude>:4927
def freeze -> Set[T]
The members as a Set, leaving the builder empty: the same as
#to_set.
<prelude>:4930
def <<(value: T) -> Self
Adds value, unless it is a member already, and returns the builder.
<prelude>:4932
def add(value: T) -> Self
Adds value, unless it is a member already, and returns the builder:
the same as #<<.
<prelude>:4935
def delete(value: T) -> Self
Removes value, if it is a member, and returns the builder.
<prelude>:4937
def include?(value: Object) -> Bool
Whether value is a member. A value of another type than the members'
is none.
<prelude>:4940
def size -> Int
The number of members.
<prelude>:4942
def empty? -> Bool
Whether there is no member.
<prelude>:4944
def each(&: (T) -> Void) -> Void
Calls the block with each member, in insertion order.
<prelude>:4946
def to_set -> Set[T]
The members as a Set, handed over without copying: the builder is left
empty, and can be filled again.
<prelude>:4949
def to_a -> Array[T]
A copy of the members as an array, in insertion order; the builder keeps them.
<prelude>:4952
def to_s -> String
The literal form of the members, as Set#inspect.
<prelude>:4954
def inspect -> String
The literal form of the members, as Set#inspect.
<prelude>:4956