Class: Sketch::Builder::Polyline
- Inherits:
-
Object
- Object
- Sketch::Builder::Polyline
- Includes:
- Geometry::DSL::Polyline
- Defined in:
- lib/sketch/builder/polyline.rb
Constant Summary
Constants included from Geometry::DSL::Polyline
Geometry::DSL::Polyline::BuildError
Instance Method Summary collapse
-
#evaluate(&block) ⇒ Polyline
Evaluate a block and return a new Path Use the trick found here www.dan-manges.com/blog/ruby-dsls-instance-eval-with-delegation to allow the DSL block to call methods in the enclosing lexical scope.
-
#first ⇒ Point
The first vertex of the Polyline.
-
#initialize(*args) ⇒ Polyline
constructor
A new instance of Polyline.
-
#last ⇒ Point
The last, or most recently added, vertex of the Polyline.
-
#method_missing(method, *args, &block) ⇒ Object
The second half of the instance_eval delegation trick mentioned at www.dan-manges.com/blog/ruby-dsls-instance-eval-with-delegation.
-
#push(arg) ⇒ Geometry
Push the given object.
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
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 |
#first ⇒ Point
Returns the first vertex of the Sketch::Builder::Polyline.
33 34 35 |
# File 'lib/sketch/builder/polyline.rb', line 33 def first @elements.first end |
#last ⇒ Point
Returns the last, or most recently added, vertex of the Sketch::Builder::Polyline.
38 39 40 |
# File 'lib/sketch/builder/polyline.rb', line 38 def last @elements.last end |
#push(arg) ⇒ Geometry
Push the given object
45 46 47 48 |
# File 'lib/sketch/builder/polyline.rb', line 45 def push(arg) @elements.push arg self end |