Class: Opal::Rewriters::Hashes::KeyDuplicatesRewriter::UniqKeysSet
- Inherits:
-
Object
- Object
- Opal::Rewriters::Hashes::KeyDuplicatesRewriter::UniqKeysSet
- Defined in:
- opal/lib/opal/rewriters/hashes/key_duplicates_rewriter.rb
Instance Method Summary collapse
- #<<(element) ⇒ Object
-
#initialize ⇒ UniqKeysSet
constructor
A new instance of UniqKeysSet.
Constructor Details
#initialize ⇒ UniqKeysSet
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 |