Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4b5cea6b6037
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1b99cd39ba4e
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Jan 9, 2018

  1. Add Set#reset

    ChrisBr committed Jan 9, 2018
    Copy the full SHA
    54b0eeb View commit details

Commits on Jan 10, 2018

  1. Merge pull request #4957 from ChrisBr/feature/set-rehash

    Add Set#reset
    kares authored Jan 10, 2018
    Copy the full SHA
    1b99cd3 View commit details
Showing with 20 additions and 1 deletion.
  1. +7 −1 core/src/main/java/org/jruby/ext/set/RubySet.java
  2. +13 −0 test/mri/test_set.rb
8 changes: 7 additions & 1 deletion core/src/main/java/org/jruby/ext/set/RubySet.java
Original file line number Diff line number Diff line change
@@ -875,6 +875,12 @@ public IRubyObject op_equal(ThreadContext context, IRubyObject other) {
return context.runtime.getFalse();
}

@JRubyMethod(name = "reset")
public IRubyObject reset(ThreadContext context) {
this.hash.rehash();
return this;
}

@JRubyMethod(name = "eql?")
public IRubyObject op_eql(ThreadContext context, IRubyObject other) {
if ( other instanceof RubySet ) {
@@ -1261,4 +1267,4 @@ final IRubyObject toRuby(Object obj) {
return JavaUtil.convertJavaToUsableRubyObject(getRuntime(), obj);
}

}
}
13 changes: 13 additions & 0 deletions test/mri/test_set.rb
Original file line number Diff line number Diff line change
@@ -734,6 +734,19 @@ def test_compare_by_identity
assert_equal(3, set.size)
assert_equal(array.uniq.sort, set.sort)
end

def test_reset
[Set, Class.new(Set)].each { |klass|
a = [1, 2]
b = [1]
set = klass.new([a, b])

b << 2
set.reset

assert_equal(klass.new([a]), set, klass.name)
}
end
end

class TC_SortedSet < Test::Unit::TestCase