Sha256: 53dcb425d361888f605137307c27e2db73bb7e722eafd5fe5e33e9ceaf048b7e

Contents?: true

Size: 900 Bytes

Versions: 50

Compression:

Stored size: 900 Bytes

Contents

# frozen_string_literal: true

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

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

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

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

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

    True.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.4.08 lib/loxxy/datatype/true.rb
loxxy-0.4.07 lib/loxxy/datatype/true.rb
loxxy-0.4.06 lib/loxxy/datatype/true.rb
loxxy-0.4.05 lib/loxxy/datatype/true.rb
loxxy-0.4.04 lib/loxxy/datatype/true.rb
loxxy-0.4.03 lib/loxxy/datatype/true.rb
loxxy-0.4.02 lib/loxxy/datatype/true.rb
loxxy-0.4.01 lib/loxxy/datatype/true.rb
loxxy-0.4.00 lib/loxxy/datatype/true.rb
loxxy-0.3.03 lib/loxxy/datatype/true.rb
loxxy-0.3.02 lib/loxxy/datatype/true.rb
loxxy-0.3.01 lib/loxxy/datatype/true.rb
loxxy-0.3.00 lib/loxxy/datatype/true.rb
loxxy-0.2.06 lib/loxxy/datatype/true.rb
loxxy-0.2.05 lib/loxxy/datatype/true.rb
loxxy-0.2.04 lib/loxxy/datatype/true.rb
loxxy-0.2.03 lib/loxxy/datatype/true.rb
loxxy-0.2.02 lib/loxxy/datatype/true.rb
loxxy-0.2.01 lib/loxxy/datatype/true.rb
loxxy-0.2.00 lib/loxxy/datatype/true.rb