|
SketchUp Ruby API Reference |
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:
The new method is used to create a new set.
set = Set.new
set - a new Set object if successful
Example
set = Set.newif (set)UI.messagebox setelseUI.messagebox "Failure"end
The clear method is used to clear all objects out of the set.
set = set.clear
set - an empty Set object
set = Set.newtoolbar = UI::Toolbar.new "Test"set = set.insert toolbarif (set.include? toolbar)UI.messagebox "Success: Contains Toolbar Object"elseUI.messagebox "Failure"endset = set.clearif (set.include? toolbar)UI.messagebox setelseUI.messagebox "Set is empty"end
The contains? method is an alias for include?. See also Set.include?
status = set.contains? object
object - a Ruby object of any type
status - true if the set contains the object, false if the set does not contain the object.
set = Set.new
toolbar = UI::Toolbar.new "Test"set = set.insert toolbarif (set.contains? toolbar)UI.messagebox "Success: Contains Toolbar Object"elseUI.messagebox "Failure"end
The delete object is used to delete or remove an object from the set.
object = set.delete object
object - the object to be deleted.
object - the object that was deleted.
set = Set.newtoolbar = UI::Toolbar.new "Test"set = set.insert toolbarif (set.include? toolbar)UI.messagebox "Success: Contains Toolbar Object"elseUI.messagebox "Failure"endset = set.delete toolbarif (set.include? toolbar)UI.messagebox setelseUI.messagebox "Set is empty"end
The each method is used to iterate through all of the objects in the set.
set.each {| item |...}
item – variables that will hold each object as it is found.
set = Set.newtoolbar = UI::Toolbar.new "Test"set = set.insert toolbarset.each { | item | UI.messagebox item }
The empty? method is used to determine whether the set is empty.
status = set.empty
status - true if the set is empty, false if it is not empty.
set = Set.newtoolbar = UI::Toolbar.new "Test"set = set.insert toolbarstatus = set.empty?if (status)UI.messagebox "Success: Set is Empty"elseUI.messagebox "Failure: Set has an Item"end
The include? method is used to determine if the set includes a particular object. This method is the same as the contains? method.
status = set.contains? object
object - a Ruby object of any type
status - true if the set contains the object, false if the set does not contain the object.
set = Set.newtoolbar = UI::Toolbar.new "Test"set = set.insert toolbarif (set.include? toolbar)\UI.messagebox "Success: Contains Toolbar Object"elseUI.messagebox "Failure"end
The insert method is used to insert an object into the set.
size = set.insert object
object - the object to be inserted into the set
size - the number of objects in the set
set = Set.newtoolbar = UI::Toolbar.new "Test"set = set.insert toolbarif (set.include? toolbar)UI.messagebox "Success: Contains Toolbar Object"elseUI.messagebox "Failure"end
The length method is an alias for size. See also Set.size.
length = set.length
length - the length (number of objects) in the set
set = Set.newtoolbar = UI::Toolbar.new "Test"set = set.insert toolbarlength = set.lengthif (length)UI.messagebox lengthelseUI.messagebox "Failure"end
The size method is used to determine the number of objects in the set.
size = set.size
size - the number of objects in the set
set = Set.newtoolbar = UI::Toolbar.new "Test"set = set.insert toolbarsize = set.sizeif (size)UI.messagebox sizeelseUI.messagebox "Failure"end
The to_a method is used to convert the array into an Array class.
array = set.to_a
array - an Array object representing the set
set = Set.newtoolbar = UI::Toolbar.new "Test"set = set.insert toolbara = set.to_aif (a)UI.messagebox aelseUI.messagebox "Failure"end