Included Modules

Class/Module Index

Set

Set implements a collection of unordered values with
no duplicates. This is a hybrid of Array's intuitive inter-operation
facilities and Hash's fast lookup.

Set is easy to use with Enumerable objects (implementing
each). Most of the initializer methods and binary operators
accept generic Enumerable objects besides
sets and arrays. An Enumerable object can be
converted to Set using the to_set
method.

The comparison operators <, >, <= and >= are implemented as
shorthand for the {proper_,}{subset?,superset?} methods. However, the
<=> operator is intentionally left out because not every pair of sets
is comparable. ({x,y} vs. {x,z} for example)

Adds the given object to the set and returns self. If the object is
already in the set, returns nil.

# File set.rb, line 320defadd?(o)
add(o) unlessinclude?(o)
end

classify()

Classifies the set by the return value of the given block and returns a
hash of {value => set of elements} pairs. The block is called once for
each element of the set, passing the element as parameter.

Deletes the given object from the set and returns self. Use
subtract to delete many items at once.

# File set.rb, line 326defdelete(o)
@hash.delete(o)
selfend

delete?(o)

Deletes the given object from the set and returns self. If the object is
not in the set, returns nil.

# File set.rb, line 333defdelete?(o)
delete(o) ifinclude?(o)
end

delete_if()

Deletes every element of the set for which block evaluates to true, and
returns self.

# File set.rb, line 339defdelete_ifblock_given?orreturnenum_for(__method__)
# @hash.delete_if should be faster, but using it breaks the order# of enumeration in subclasses.select { |o|yieldo }.each { |o|@hash.delete(o) }
selfend

Deletes every element of the set for which block evaluates to false, and
returns self.

# File set.rb, line 349defkeep_ifblock_given?orreturnenum_for(__method__)
# @hash.keep_if should be faster, but using it breaks the order of# enumeration in subclasses.reject { |o|yieldo }.each { |o|@hash.delete(o) }
selfend