Ruby Set Functions
EditRocket provides the following information on Set functions in the Ruby source code builder.
add?(o) - Adds the given object to the set and returns self. If the object is already in the set, returns nil.
add(o) - Adds the given object to the set and returns self. Use merge to add several elements at once.
classify( {|o| ...} - 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.
clear() - Removes all elements and returns self.
collect!() - Do collect() destructively.
delete?(o) - Deletes the given object from the set and returns self. If the object is not in the set, returns nil.
delete(o) - Deletes the given object from the set and returns self. Use subtract to delete several items at once.
delete_if() - Deletes every element of the set for which block evaluates to true, and returns self.
difference(enum) - "Alias for #-"
divide(&func) - Divides the set into a set of subsets according to the commonality defined by the given block.
each() - Calls the given block once for each element in the set, passing the element as parameter.
empty?() - Returns true if the set contains no elements.
flatten!() - Equivalent to Set#flatten, but replaces the receiver with the result in place. Returns nil if no modifications were made.
flatten() - Returns a new set that is a copy of the set, flattening each containing set recursively.
include?(o) - Returns true if the set contains the given object.
initialize_copy(orig) - Copy internal hash.
inspect() - "Returns a string containing a human-readable representation of the set. ("#<Set: {element1, element2, ...}>")"
intersection(enum) - "Alias for #&"
length() - "Alias for #size"
map!() - "Alias for #collect!"
member?(o) - "Alias for #include?"
merge(enum) - Merges the elements of the given enumerable object to the set and returns self.
new(enum = nil) - Creates a new set containing the elements of the given enumerable object.
proper_subset?(set) - Returns true if the set is a proper subset of the given set.
proper_superset?(set) - Returns true if the set is a proper superset of the given set.
reject!() - Equivalent to Set#delete_if, but returns nil if no changes were made.
replace(enum) - Replaces the contents of the set with the contents of the given enumerable object and returns self.
size() - Returns the number of elements.
subset?(set) - Returns true if the set is a subset of the given set.
subtract(enum) - Deletes every element that appears in the given enumerable object and returns self.
superset?(set) - Returns true if the set is a superset of the given set.
to_a() - Converts the set to an array. The order of elements is uncertain.
union(enum) - "Alias for #|"