Class: Sketch::Builder::Polyline

Inherits:
Object
  • Object
show all
Includes:
Geometry::DSL::Polyline
Defined in:
lib/sketch/builder/polyline.rb

Direct Known Subclasses

Path, Polygon

Constant Summary

Constants included from Geometry::DSL::Polyline

Geometry::DSL::Polyline::BuildError

Instance Method Summary collapse

Methods included from Geometry::DSL::Polyline

#close, #closed?, #down, #horizontal_to, #left, #move_to, #move_x, #move_y, #right, #start_at, #up, #vertical_to

Constructor Details

#initialize(*args) ⇒ Polyline

Returns a new instance of Polyline.



10
11
12
# File 'lib/sketch/builder/polyline.rb', line 10

def initialize(*args)
		@elements = args || []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

The second half of the instance_eval delegation trick mentioned at

http://www.dan-manges.com/blog/ruby-dsls-instance-eval-with-delegation


28
29
30
# File 'lib/sketch/builder/polyline.rb', line 28

def method_missing(method, *args, &block)
		@self_before_instance_eval.send method, *args, &block
end

Instance Method Details

#evaluate(&block) ⇒ Polyline

Evaluate a block and return a new Sketch::Builder::Path

Use the trick found here http://www.dan-manges.com/blog/ruby-dsls-instance-eval-with-delegation
to allow the DSL block to call methods in the enclosing *lexical* scope

Returns:



18
19
20
21
22
23
24
# File 'lib/sketch/builder/polyline.rb', line 18

def evaluate(&block)
		if block_given?
 @self_before_instance_eval = eval "self", block.binding
 self.instance_eval &block
		end
		Sketch::Polyline.new(*@elements)
end

#firstPoint

Returns the first vertex of the Sketch::Builder::Polyline.

Returns:



33
34
35
# File 'lib/sketch/builder/polyline.rb', line 33

def first
		@elements.first
end

#lastPoint

Returns the last, or most recently added, vertex of the Sketch::Builder::Polyline.

Returns:



38
39
40
# File 'lib/sketch/builder/polyline.rb', line 38

def last
		@elements.last
end

#push(arg) ⇒ Geometry

Push the given object

Parameters:

Returns:



45
46
47
48
# File 'lib/sketch/builder/polyline.rb', line 45

def push(arg)
		@elements.push arg
		self
end