Sha256: 53dcb425d361888f605137307c27e2db73bb7e722eafd5fe5e33e9ceaf048b7e

Contents?: true

Size: 900 Bytes

Versions: 51

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

51 entries across 51 versions & 1 rubygems

Version Path
loxxy-0.0.27 lib/loxxy/datatype/true.rb
loxxy-0.0.26 lib/loxxy/datatype/true.rb
loxxy-0.0.25 lib/loxxy/datatype/true.rb
loxxy-0.0.24 lib/loxxy/datatype/true.rb
loxxy-0.0.23 lib/loxxy/datatype/true.rb
loxxy-0.0.22 lib/loxxy/datatype/true.rb
loxxy-0.0.21 lib/loxxy/datatype/true.rb
loxxy-0.0.20 lib/loxxy/datatype/true.rb
loxxy-0.0.19 lib/loxxy/datatype/true.rb
loxxy-0.0.18 lib/loxxy/datatype/true.rb
loxxy-0.0.17 lib/loxxy/datatype/true.rb