class Set |
Parent: Object |
|
Methods: new, clear, contains?, delete, each, empty?, include?, insert, length, size, to_a |
|
Sample Code: |
|
Class Methods |
new |
The new method is used to create a new set. |
Syntax: |
set = Set.new |
Arguments: |
|
Return Value: |
set - a new Set object if successful |
Comments: |
|
Example: |
set
= Set.new |
Instance Methods |
clear |
The clear method is used to clear all objects out of the set. |
Syntax: |
set = set.clear |
Arguments: |
|
Return Value: |
set - an empty Set object |
Comments: |
|
Example: |
set
= Set.new |
contains? |
The contains? method is an alias for include?. See also Set.include? |
Syntax: |
status = set.contains? object |
Arguments: |
object - a Ruby object of any type |
Return Value: |
status - true if the set contains the object, false if the set does not contain the object. |
Comments: |
|
Example: |
set = Set.new |
delete |
The delete object is used to delete or remove an object from the set. |
Syntax: |
object = set.delete object |
Arguments: |
object - the object to be deleted. |
Return Value: |
object - the object that was deleted. |
Comments: |
|
Example: |
set
= Set.new |
each |
The each method is used to iterate through all of the objects in the set. |
Syntax: |
set.each {| item |...} |
Arguments: |
|
Return Value: |
item – variables that will hold each object as it is found. |
Comments: |
|
Example: |
set
= Set.new |
empty? |
The empty? method is used to determine whether the set is empty. |
Syntax: |
status = set.empty |
Arguments: |
|
Return Value: |
status - true if the set is empty, false if it is not empty. |
Comments: |
|
Example: |
set
= Set.new |
include? |
The include? method is used to determine if the set includes a particular object. This method is the same as the contains? method. |
Syntax: |
status = set.contains? object |
Arguments: |
object - a Ruby object of any type |
Return Value: |
status - true if the set contains the object, false if the set does not contain the object. |
Comments: |
|
Example: |
set
= Set.new |
insert |
The insert method is used to insert an object into the set. |
Syntax: |
size = set.insert object |
Arguments: |
object - the object to be inserted into the set |
Return Value: |
size - the number of objects in the set |
Comments: |
|
Example: |
set
= Set.new |
length |
The length method is an alias for size. See also Set.size. |
Syntax: |
length = set.length |
Arguments: |
|
Return Value: |
length - the length (number of objects) in the set |
Comments: |
|
Example: |
set
= Set.new |
size |
The size method is used to determine the number of objects in the set. |
Syntax: |
size = set.size |
Arguments: |
|
Return Value: |
size - the number of objects in the set |
Comments: |
|
Example: |
set
= Set.new |
to_a |
The to_a method is used to convert the array into an Array class. |
Syntax: |
array = set.to_a |
Arguments: |
|
Return Value: |
array - an Array object representing the set |
Comments: |
|
Example: |
set
= Set.new |