Class: Loxxy::Datatype::BuiltinDatatype
- Inherits:
-
Object
- Object
- Loxxy::Datatype::BuiltinDatatype
- Defined in:
- lib/loxxy/datatype/builtin_datatype.rb
Overview
Abstract class that generalizes a value from a Lox built-in data types. An instance acts merely as a wrapper around a Ruby representation of the value.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
The Ruby representation.
Instance Method Summary collapse
-
#! ⇒ Datatype::Boolean
Negation ('not') Returns a boolean with opposite truthiness value.
-
#!=(other) ⇒ Datatype::Boolean
Check for inequality of this object with another Lox object.
-
#accept(visitor) ⇒ Object
Part of the 'visitee' role in Visitor design pattern.
-
#and(operand2) ⇒ Object
Returns the first falsey argument (if any), otherwise returns the last truthy argument.
-
#falsey? ⇒ Boolean
Is the value considered falsey in Lox? Rule: false and nil are falsey and everything else is truthy.
-
#initialize(aValue) ⇒ BuiltinDatatype
constructor
Constructor.
-
#or(operand2) ⇒ Object
Returns the first truthy argument (if any), otherwise returns the last falsey argument.
-
#to_str ⇒ String
Method called from Lox to obtain the text representation of the boolean.
-
#truthy? ⇒ Boolean
Is the value considered truthy in Lox? Rule: false and nil are falsey and everything else is truthy.
Constructor Details
#initialize(aValue) ⇒ BuiltinDatatype
Constructor. Initialize a Lox value from one of its built-in data type.
13 14 15 |
# File 'lib/loxxy/datatype/builtin_datatype.rb', line 13 def initialize(aValue) @value = validated_value(aValue) end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns The Ruby representation.
10 11 12 |
# File 'lib/loxxy/datatype/builtin_datatype.rb', line 10 def value @value end |
Instance Method Details
#! ⇒ Datatype::Boolean
Negation ('not') Returns a boolean with opposite truthiness value.
41 42 43 |
# File 'lib/loxxy/datatype/builtin_datatype.rb', line 41 def ! falsey? ? True.instance : False.instance end |
#!=(other) ⇒ Datatype::Boolean
Check for inequality of this object with another Lox object
34 35 36 |
# File 'lib/loxxy/datatype/builtin_datatype.rb', line 34 def !=(other) !(self == other) end |
#accept(visitor) ⇒ Object
Part of the 'visitee' role in Visitor design pattern.
67 68 69 |
# File 'lib/loxxy/datatype/builtin_datatype.rb', line 67 def accept(visitor) visitor.visit_builtin(self) end |
#and(operand2) ⇒ Object
Returns the first falsey argument (if any), otherwise returns the last truthy argument.
48 49 50 |
# File 'lib/loxxy/datatype/builtin_datatype.rb', line 48 def and(operand2) falsey? ? self : logical_2nd_arg(operand2) end |
#falsey? ⇒ Boolean
Is the value considered falsey in Lox? Rule: false and nil are falsey and everything else is truthy. This test used in conditional statements (i.e. if, while)
20 21 22 |
# File 'lib/loxxy/datatype/builtin_datatype.rb', line 20 def falsey? false # Default implementation end |
#or(operand2) ⇒ Object
Returns the first truthy argument (if any), otherwise returns the last falsey argument.
55 56 57 |
# File 'lib/loxxy/datatype/builtin_datatype.rb', line 55 def or(operand2) truthy? ? self : logical_2nd_arg(operand2) end |
#to_str ⇒ String
Method called from Lox to obtain the text representation of the boolean.
61 62 63 |
# File 'lib/loxxy/datatype/builtin_datatype.rb', line 61 def to_str value.to_s # Default implementation... end |
#truthy? ⇒ Boolean
Is the value considered truthy in Lox? Rule: false and nil are falsey and everything else is truthy. This test used in conditional statements (i.e. if, while)
27 28 29 |
# File 'lib/loxxy/datatype/builtin_datatype.rb', line 27 def truthy? true # Default implementation end |