Sha256: bea23b8e214847b866bc81900baac32a78e1123362f8fb0a5ab4916c252af4c7

Contents?: true

Size: 935 Bytes

Versions: 7

Compression:

Stored size: 935 Bytes

Contents

# frozen_string_literal: true

require_relative 'builtin_datatype'

module Loxxy
  module Datatype
    # Class for representing a Lox string of characters value.
    class LXString < BuiltinDatatype
      # Compare a Lox String with another Lox (or genuine Ruby) String
      # @param other [Datatype::LxString, String]
      # @return [Boolean]
      def ==(other)
        case other
          when LXString
            value == other.value
          when String
            value == other
        else
          err_msg = "Cannot compare a #{self.class} with #{other.class}"
          raise StandardError, err_msg
        end
      end

      protected

      def validated_value(aValue)
        unless aValue.is_a?(String)
          raise StandardError, "Invalid number value #{aValue}"
        end

        # Remove double quotes delimiter
        aValue.gsub(/(^")|("$)/, '')
      end
    end # class
  end # module
end # module

Version data entries

7 entries across 7 versions & 1 rubygems

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