Sha256: f35651a286f547c66879c6441e31a1f2e4c592608a68ff0f96246f452f4a1a6d

Contents?: true

Size: 587 Bytes

Versions: 1

Compression:

Stored size: 587 Bytes

Contents

# frozen_string_literal: true

module TJSON
  # TJSON object type (i.e. hash/dict-alike)
  class Object < ::Hash
    def []=(name, value)
      unless name.start_with?("s:", "b16:", "b64:")
        raise TJSON::ParseError, "invalid tag on object name: #{name[/\A(.*?):/, 1]}" if name.include?(":")
        raise TJSON::ParseError, "no tag found on object name: #{name.inspect}"
      end

      name = TJSON::Parser.value(name)
      raise TJSON::DuplicateNameError, "duplicate member name: #{name.inspect}" if key?(name)

      super(name, TJSON::Parser.value(value))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tjson-0.1.0 lib/tjson/object.rb