Class: Opal::Rewriters::Hashes::KeyDuplicatesRewriter::UniqKeysSet

Inherits:
Object
  • Object
show all
Defined in:
opal/lib/opal/rewriters/hashes/key_duplicates_rewriter.rb

Instance Method Summary collapse

Constructor Details

#initializeUniqKeysSet

Returns a new instance of UniqKeysSet



41
42
43
# File 'opal/lib/opal/rewriters/hashes/key_duplicates_rewriter.rb', line 41

def initialize
  @set = Set.new
end

Instance Method Details

#<<(element) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'opal/lib/opal/rewriters/hashes/key_duplicates_rewriter.rb', line 45

def <<(element)
  if @set.include?(element)
    key, _ = *element
    key = element.type == :str ? key.inspect : ":#{key}"
    Kernel.warn "warning: key #{key} is duplicated and overwritten"
  else
    @set << element
  end
end