Class: Optical::System
- Inherits:
-
Object
- Object
- Optical::System
- Defined in:
- lib/optical/system.rb
Overview
An Optical System is a set of Optical Elements, generally arranged in a line.
Defined Under Namespace
Classes: Spacer
Instance Attribute Summary collapse
-
#elements ⇒ Object
Returns the value of attribute elements.
-
#spacing ⇒ Number
The default spacing to add between newly added elements.
Class Method Summary collapse
-
.spacer(space) ⇒ Object
Convenience method for creating a new Spacer.
Instance Method Summary collapse
-
#initialize ⇒ System
constructor
A new instance of System.
-
#push(element) ⇒ System
Append a new Optical element.
Constructor Details
#initialize ⇒ System
Returns a new instance of System.
19 20 21 |
# File 'lib/optical/system.rb', line 19 def initialize @elements = [] end |
Instance Attribute Details
#elements ⇒ Object
Returns the value of attribute elements.
8 9 10 |
# File 'lib/optical/system.rb', line 8 def elements @elements end |
#spacing ⇒ Number
Returns the default spacing to add between newly added elements.
12 13 14 |
# File 'lib/optical/system.rb', line 12 def spacing @spacing end |
Class Method Details
Instance Method Details
#push(element) ⇒ System
Append a new Optical element
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/optical/system.rb', line 25 def push(element) if element.is_a?(Numeric) @elements.push Spacer.new(element) elsif element.is_a?(Spacer) @elements.push element else @elements.push Spacer.new(spacing) if spacing && !(elements.empty? || elements.last.is_a?(Spacer)) @elements.push element end self end |