Sha256: 04862946e3fe95dfe85bbb53bafbe1b548f030f2735b56b923a5a4656c24f4fa

Contents?: true

Size: 738 Bytes

Versions: 5

Compression:

Stored size: 738 Bytes

Contents

# frozen_string_literal: true

require_relative 'atomic_term'

module MiniKraken
  module Core
    # A specialized atomic term that represents an boolean (true/false) value.
    # in MiniKraken
    class KBoolean < AtomicTerm
      # @param aValue [Boolean, Symbol] Ruby representation of boolean value
      def initialize(aValue)
        super(validated_value(aValue))
      end

      private

      def validated_value(aValue)
        case aValue
          when true, false
            aValue
          when :"#t", '#t'
            true
          when :"#f", '#f'
            false
          else
            raise StandardError, "Invalid boolean literal '#{aValue}'"
        end
      end
    end # class
  end # module
end # module

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mini_kraken-0.2.01 lib/mini_kraken/core/k_boolean.rb
mini_kraken-0.2.00 lib/mini_kraken/core/k_boolean.rb
mini_kraken-0.1.13 lib/mini_kraken/core/k_boolean.rb
mini_kraken-0.1.12 lib/mini_kraken/core/k_boolean.rb
mini_kraken-0.1.11 lib/mini_kraken/core/k_boolean.rb