Module: Java::JavaUtil::Set
- Defined in:
- lib/caruby/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.
124 125 126 |
# File 'lib/caruby/import/java.rb', line 124 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.
133 134 135 136 137 138 |
# File 'lib/caruby/import/java.rb', line 133 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 |