Class: Loxxy::Datatype::Nil

Inherits:
BuiltinDatatype show all
Includes:
Singleton
Defined in:
lib/loxxy/datatype/nil.rb

Overview

Class for representing a Lox nil "value".

Instance Attribute Summary

Attributes inherited from BuiltinDatatype

#value

Instance Method Summary collapse

Methods inherited from BuiltinDatatype

#!, #!=, #accept, #and, #or

Constructor Details

#initializeNil

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.

Parameters:

Returns:



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)

Returns:



28
29
30
# File 'lib/loxxy/datatype/nil.rb', line 28

def falsey?
  true
end

#to_strString

Method called from Lox to obtain the text representation of nil.

Returns:

  • (String)


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)

Returns:



35
36
37
# File 'lib/loxxy/datatype/nil.rb', line 35

def truthy?
  false
end