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.1.17 lib/loxxy/datatype/true.rb
loxxy-0.1.16 lib/loxxy/datatype/true.rb
loxxy-0.1.15 lib/loxxy/datatype/true.rb
loxxy-0.1.14 lib/loxxy/datatype/true.rb
loxxy-0.1.13 lib/loxxy/datatype/true.rb
loxxy-0.1.12 lib/loxxy/datatype/true.rb
loxxy-0.1.11 lib/loxxy/datatype/true.rb
loxxy-0.1.10 lib/loxxy/datatype/true.rb
loxxy-0.1.09 lib/loxxy/datatype/true.rb
loxxy-0.1.08 lib/loxxy/datatype/true.rb
loxxy-0.1.07 lib/loxxy/datatype/true.rb
loxxy-0.1.06 lib/loxxy/datatype/true.rb
loxxy-0.1.05 lib/loxxy/datatype/true.rb
loxxy-0.1.04 lib/loxxy/datatype/true.rb
loxxy-0.1.03 lib/loxxy/datatype/true.rb
loxxy-0.1.02 lib/loxxy/datatype/true.rb
loxxy-0.1.01 lib/loxxy/datatype/true.rb
loxxy-0.1.0 lib/loxxy/datatype/true.rb
loxxy-0.0.28 lib/loxxy/datatype/true.rb
loxxy-0.0.27 lib/loxxy/datatype/true.rb