Sha256: 3a0f7ca6654e870cccd0d3deeba96205e0b9adf7dc72cdfb1f2832b787a0af85

Contents?: true

Size: 724 Bytes

Versions: 3

Compression:

Stored size: 724 Bytes

Contents

# frozen_string_literal: true

require_relative 'basic_numeric'

module Basic101

  class BasicInteger < BasicNumeric

    def self.from_bool(b)
      new(b ? -1 : 0)
    end

    def to_integer
      self
    end

    def to_float
      BasicFloat.new(@value)
    end

    def and(other)
      self.class.new(value & other.to_integer.value)
    end

    def or(other)
      self.class.new(value | other.to_integer.value)
    end

    def not
      self.class.new(~value)
    end

    def chr
      raise InvalidArgumentError unless (0..255).include?(@value)
      BasicString.new(@value.chr)
    end

    def str
      BasicString.new(@value.to_s)
    end

    private

    def format
      @value.to_s
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
basic101-1.0.2 lib/basic101/basic_integer.rb
basic101-1.0.1 lib/basic101/basic_integer.rb
basic101-1.0.0 lib/basic101/basic_integer.rb