Class: Loxxy::BackEnd::UnaryOperator

Inherits:
Object
  • Object
show all
Defined in:
lib/loxxy/back_end/unary_operator.rb

Overview

A Lox unary operator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aName, theSignatures) ⇒ UnaryOperator

Returns a new instance of UnaryOperator.

Parameters:

  • aName (String)

    "name" of operator

  • theSignatures (Array<Class>)

    allowed signatures



17
18
19
20
# File 'lib/loxxy/back_end/unary_operator.rb', line 17

def initialize(aName, theSignatures)
  @name = aName
  @signatures = theSignatures
end

Instance Attribute Details

#nameString (readonly)

Returns text representation of the operator.

Returns:

  • (String)

    text representation of the operator



10
11
12
# File 'lib/loxxy/back_end/unary_operator.rb', line 10

def name
  @name
end

#signaturesArray<Class> (readonly)

Returns:

  • (Array<Class>)


13
14
15
# File 'lib/loxxy/back_end/unary_operator.rb', line 13

def signatures
  @signatures
end

Instance Method Details

#validate_operand(operand1) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/loxxy/back_end/unary_operator.rb', line 22

def validate_operand(operand1)
  compliant = signatures.find { |some_type| operand1.kind_of?(some_type) }

  unless compliant
    err = Loxxy::RuntimeError
    # if signatures.size == 1
    raise err, "Operand must be a #{datatype_name(signatures[0])}."
    # end
  end
end