Sha256: 2494c0dd74b1ee26a58453429971ff2d6e49f88a962c22f15d2b4dd0c80f023a

Contents?: true

Size: 1.32 KB

Versions: 50

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require 'singleton' # Use the Singleton design pattern
require_relative 'boolean'

module Loxxy
  module Datatype
    # Class for representing a Lox false value.
    class False < Boolean
      include Singleton # Make a singleton class

      # Build the sole instance
      def initialize
        super(false)
      end

      # Is this object representing a false value in Lox?
      # @return [TrueClass]
      def false?
        true
      end

      # 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)
      def falsey?
        true
      end

      # 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)
      def truthy?
        false
      end

      # Check for equality of a Lox False with another Lox object
      # @param other [Datatype::BuiltinDatatype, FalseClass, Object]
      # @return [Datatype::Boolean]
      def ==(other)
        falsey = other.kind_of?(False) || other.kind_of?(FalseClass)
        falsey ? True.instance : False.instance
      end
    end # class

    False.instance.freeze # Make the sole instance immutable
  end # module
end # module

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
loxxy-0.1.17 lib/loxxy/datatype/false.rb
loxxy-0.1.16 lib/loxxy/datatype/false.rb
loxxy-0.1.15 lib/loxxy/datatype/false.rb
loxxy-0.1.14 lib/loxxy/datatype/false.rb
loxxy-0.1.13 lib/loxxy/datatype/false.rb
loxxy-0.1.12 lib/loxxy/datatype/false.rb
loxxy-0.1.11 lib/loxxy/datatype/false.rb
loxxy-0.1.10 lib/loxxy/datatype/false.rb
loxxy-0.1.09 lib/loxxy/datatype/false.rb
loxxy-0.1.08 lib/loxxy/datatype/false.rb
loxxy-0.1.07 lib/loxxy/datatype/false.rb
loxxy-0.1.06 lib/loxxy/datatype/false.rb
loxxy-0.1.05 lib/loxxy/datatype/false.rb
loxxy-0.1.04 lib/loxxy/datatype/false.rb
loxxy-0.1.03 lib/loxxy/datatype/false.rb
loxxy-0.1.02 lib/loxxy/datatype/false.rb
loxxy-0.1.01 lib/loxxy/datatype/false.rb
loxxy-0.1.0 lib/loxxy/datatype/false.rb
loxxy-0.0.28 lib/loxxy/datatype/false.rb
loxxy-0.0.27 lib/loxxy/datatype/false.rb