Class: Loxxy::Datatype::Nil
- Inherits:
-
BuiltinDatatype
- Object
- BuiltinDatatype
- Loxxy::Datatype::Nil
- Includes:
- Singleton
- Defined in:
- lib/loxxy/datatype/nil.rb
Overview
Class for representing a Lox nil "value".
Instance Attribute Summary
Attributes inherited from BuiltinDatatype
Instance Method Summary collapse
-
#==(other) ⇒ Datatype::Boolean
Check the equality with another object.
-
#falsey? ⇒ Boolean
Is the value considered falsey in Lox? Rule: false and nil are falsey and everything else is truthy.
-
#initialize ⇒ Nil
constructor
Build the sole instance.
-
#to_str ⇒ String
Method called from Lox to obtain the text representation of nil.
-
#truthy? ⇒ Boolean
Is the value considered truthy in Lox? Rule: false and nil are falsey and everything else is truthy.
Methods inherited from BuiltinDatatype
Constructor Details
#initialize ⇒ Nil
Build the sole instance
13 14 15 |
# File 'lib/loxxy/datatype/nil.rb', line 13 def initialize super(nil) end |
Instance Method Details
#==(other) ⇒ Datatype::Boolean
Check the equality with another object.
20 21 22 23 |
# File 'lib/loxxy/datatype/nil.rb', line 20 def ==(other) is_nil = other.kind_of?(Nil) || other.kind_of?(NilClass) is_nil ? True.instance : False.instance 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)
28 29 30 |
# File 'lib/loxxy/datatype/nil.rb', line 28 def falsey? true end |
#to_str ⇒ String
Method called from Lox to obtain the text representation of nil.
41 42 43 |
# File 'lib/loxxy/datatype/nil.rb', line 41 def to_str 'nil' 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)
35 36 37 |
# File 'lib/loxxy/datatype/nil.rb', line 35 def truthy? false end |