Class: YaspTree

Inherits:
Object
  • Object
show all
Defined in:
lib/YASP/yasp_tree.rb

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ YaspTree

Returns a new instance of YaspTree.



3
4
5
6
# File 'lib/YASP/yasp_tree.rb', line 3

def initialize(block)
	@head = Command.new(nil, [])
	process(block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/YASP/yasp_tree.rb', line 28

def method_missing(m, *args, &block)
	element = Command.new(m, args)
	add(element)

	if block_given?
		previous_head = @head
		@head = element

		self.instance_eval(&block)

		@head = previous_head
	end
end

Instance Method Details

#add(obj) ⇒ Object



12
13
14
# File 'lib/YASP/yasp_tree.rb', line 12

def add(obj)
	@head << obj
end

#assign(&block) ⇒ Object



24
25
26
# File 'lib/YASP/yasp_tree.rb', line 24

def assign(&block)
	YaspTree.new(block).tree
end

#process(block) ⇒ Object



20
21
22
# File 'lib/YASP/yasp_tree.rb', line 20

def process(block)
	instance_eval(&block)
end

#to_scadObject



16
17
18
# File 'lib/YASP/yasp_tree.rb', line 16

def to_scad
	@head.to_scad(0);
end

#treeObject



8
9
10
# File 'lib/YASP/yasp_tree.rb', line 8

def tree
	@head
end