Class: Loxxy::BackEnd::Variable

Inherits:
Object
  • Object
show all
Includes:
Entry
Defined in:
lib/loxxy/back_end/variable.rb

Overview

Representation of a Lox variable. It is a named slot that can be associated with a value at the time.

Instance Attribute Summary collapse

Attributes included from Entry

#name

Instance Method Summary collapse

Methods included from Entry

#init_name

Constructor Details

#initialize(aName, aValue = Datatype::Nil.instance) ⇒ Variable

Create a variable with given name and initial value

Parameters:

  • aName (String)

    The name of the variable

  • aValue (Datatype::BuiltinDatatype) (defaults to: Datatype::Nil.instance)

    the initial assigned value



19
20
21
22
# File 'lib/loxxy/back_end/variable.rb', line 19

def initialize(aName, aValue = Datatype::Nil.instance)
  init_name(aName)
  assign(aValue)
end

Instance Attribute Details

#valueDatatype::BuiltinDatatype (readonly)

Returns the value assigned to the variable.

Returns:



14
15
16
# File 'lib/loxxy/back_end/variable.rb', line 14

def value
  @value
end

Instance Method Details

#assign(aValue) ⇒ Object

Parameters:



25
26
27
# File 'lib/loxxy/back_end/variable.rb', line 25

def assign(aValue)
  @value = aValue
end