Class: Rubulator::Variable

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

Overview

Store and retrieve the value of a variable.

Instance Method Summary collapse

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_fObject

Raises:



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