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

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

Instance Method Summary collapse

Constructor Details

#initializeUniqKeysSet

Returns a new instance of UniqKeysSet.



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

def initialize
  @set = Set.new
end

Instance Method Details

#<<(element) ⇒ Object



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

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