Class: Rubulator::Variable
- Inherits:
-
Object
- Object
- Rubulator::Variable
- Defined in:
- lib/rubulator.rb
Overview
Store and retrieve the value of a variable.
Instance Method Summary collapse
-
#initialize(name, value = nil) ⇒ Variable
constructor
A new instance of Variable.
- #store(value) ⇒ Object
- #to_f ⇒ Object
Constructor Details
#initialize(name, value = nil) ⇒ Variable
Returns a new instance of Variable.
10 11 12 13 |
# File 'lib/rubulator.rb', line 10 def initialize(name, value = nil) @name = name @value = value end |
Instance Method Details
#store(value) ⇒ Object
15 16 17 |
# File 'lib/rubulator.rb', line 15 def store(value) @value = value.to_f end |
#to_f ⇒ Object
19 20 21 22 23 |
# File 'lib/rubulator.rb', line 19 def to_f raise CalculationError, "Variable '#{@name}' not set" unless @value @value.to_f end |