Sha256: cb3a3b75cc04116037decdb3f7c8ec1c7a3bef08757e591f4cf743257dbd6acc

Contents?: true

Size: 599 Bytes

Versions: 9

Compression:

Stored size: 599 Bytes

Contents

# frozen_string_literal: true

require_relative 'builtin_datatype'

module Loxxy
  module Datatype
    # Class for representing a Lox numeric value.
    class Number < BuiltinDatatype
      protected

      def validated_value(aValue)
        case aValue
          when Integer, Numeric
            result = aValue
          when /^-?\d+$/
            result = aValue.to_i
          when /^-?\d+\.\d+$/
            result = aValue.to_f
          else
            raise StandardError, "Invalid number value #{aValue}"
        end

        result
      end
    end # class
  end # module
end # module

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
loxxy-0.0.13 lib/loxxy/datatype/number.rb
loxxy-0.0.12 lib/loxxy/datatype/number.rb
loxxy-0.0.11 lib/loxxy/datatype/number.rb
loxxy-0.0.10 lib/loxxy/datatype/number.rb
loxxy-0.0.9 lib/loxxy/datatype/number.rb
loxxy-0.0.8 lib/loxxy/datatype/number.rb
loxxy-0.0.7 lib/loxxy/datatype/number.rb
loxxy-0.0.6 lib/loxxy/datatype/number.rb
loxxy-0.0.5 lib/loxxy/datatype/number.rb