Module: Java::JavaUtil::Set
- Defined in:
- lib/jinx/import/java.rb
Instance Method Summary collapse
-
#==(other) ⇒ Object
Returns whether this Set has the same content as the other Java Set or Ruby Set.
-
#merge(other) ⇒ Object
(also: #merge!)
Merges the other Enumerable into this Set.
Instance Method Details
#==(other) ⇒ Object
Returns whether this Set has the same content as the other Java Set or Ruby Set.
83 84 85 |
# File 'lib/jinx/import/java.rb', line 83 def ==(other) ::Set === other ? (size == other.size and all? { |item| other.include?(item) }) : equals(other) end |
#merge(other) ⇒ Object Also known as: merge!
Merges the other Enumerable into this Set. Returns this modified Set.
This method conforms to the Ruby Set merge contract rather than the Ruby List and Hash merge contract. Ruby Set merge modifies the Set in-place, whereas Ruby List and Hash merge return a new collection.
92 93 94 95 96 97 |
# File 'lib/jinx/import/java.rb', line 92 def merge(other) return self if other.nil? raise ArgumentError.new("Merge argument must be enumerable: #{other}") unless Enumerable === other other.each { |item| self << item } self end |