SketchUp  Ruby API Reference 

Class Index

Method Index

Developers Guide

Examples

Set class

 The set class represents a collection of unique objects.

Parent: Object 

Methods: new, clear, contains?, delete, each, empty?, include? , insert, length, size, to_a

Example Code:

Class Methods


new

The new method is used to create a new set.

Syntax

set = Set.new

Return Value

set - a new Set object if successful

Example

set = Set.new
if (set)
UI.messagebox set
else
UI.messagebox "Failure"
end

Instance Methods


clear

The clear method is used to clear all objects out of the set.

Syntax

set = set.clear

Return Value

set - an empty Set object

Example

set = Set.new
toolbar = UI::Toolbar.new "Test"      
set = set.insert toolbar
if (set.include? toolbar)
UI.messagebox "Success: Contains Toolbar Object"
else
UI.messagebox "Failure"
end
set = set.clear        
if (set.include? toolbar)
UI.messagebox set
else
UI.messagebox "Set is empty"
end

 

 


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.

Example

set = Set.new
toolbar = UI::Toolbar.new "Test"
set = set.insert toolbar
if (set.contains? toolbar)
UI.messagebox "Success: Contains Toolbar Object"
else
UI.messagebox "Failure"
end

 

 


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.

Example

set = Set.new
toolbar = UI::Toolbar.new "Test"      
set = set.insert toolbar
if (set.include? toolbar)
UI.messagebox "Success: Contains Toolbar Object"
else
UI.messagebox "Failure"
end
set = set.delete toolbar
if (set.include? toolbar)
UI.messagebox set
else
UI.messagebox "Set is empty"
end

 

 


each 

The each method is used to iterate through all of the objects in the set.

Syntax

set.each {| item |...} 

Return Value

item – variables that will hold each object as it is found.

Example

set = Set.new 
toolbar = UI::Toolbar.new "Test"
set = set.insert toolbar
set.each { | item | UI.messagebox item }

 

 


empty? 

The empty? method is used to determine whether the set is empty.

Syntax

status = set.empty

Return Value

status - true if the set is empty, false if it is not empty.

Example

set = Set.new
toolbar = UI::Toolbar.new "Test"
set = set.insert toolbar
status = set.empty?
if (status)
UI.messagebox "Success: Set is Empty"
else
UI.messagebox "Failure: Set has an Item"
end

 

 


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.

Example 

set = Set.new
toolbar = UI::Toolbar.new "Test"
set = set.insert toolbar
if (set.include? toolbar)\
UI.messagebox "Success: Contains Toolbar Object"
else
UI.messagebox "Failure"
end

 

 


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

Example

set = Set.new
toolbar = UI::Toolbar.new "Test"
set = set.insert toolbar
if (set.include? toolbar)
UI.messagebox "Success: Contains Toolbar Object"
else
UI.messagebox "Failure"
end

 

 


length 

The length method is an alias for size. See also Set.size.

Syntax

length = set.length

Return Value

length - the length (number of objects) in the set

Example

set = Set.new
toolbar = UI::Toolbar.new "Test"      
set = set.insert toolbar
length = set.length
if (length)
UI.messagebox length
else
UI.messagebox "Failure"
end

 

 


size 

The size method is used to determine the number of objects in the set.

Syntax

size = set.size

Return Value

size - the number of objects in the set

Example

set = Set.new
toolbar = UI::Toolbar.new "Test"
set = set.insert toolbar
size = set.size
if (size)
UI.messagebox size
else
UI.messagebox "Failure"
end

 

 


to_a 

The to_a method is used to convert the array into an Array class.

Syntax

array = set.to_a

Return Value

array - an Array object representing the set

Example 

set = Set.new
toolbar = UI::Toolbar.new "Test"
set = set.insert toolbar
a = set.to_a
if (a)
UI.messagebox a
else
UI.messagebox "Failure"
end

 

SketchUp  Ruby API Reference: Set

© Google Inc. 2007 sketchup.google.com