Sha256: 1ded25ada7b66939e786df29ebb1f09f4c070f32fa15fe214424f5270ea25734

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

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

      # Method called from Lox to obtain the text representation of the object.
      # @return [String]
      def to_str
        value
      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

2 entries across 2 versions & 1 rubygems

Version Path
loxxy-0.0.13 lib/loxxy/datatype/lx_string.rb
loxxy-0.0.12 lib/loxxy/datatype/lx_string.rb