Skip to content

Commit

Permalink
Add Set#reset
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBr committed Jan 9, 2018
1 parent 4b5cea6 commit 5f7e117
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/src/main/java/org/jruby/ext/set/RubySet.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.jruby.runtime.marshal.MarshalStream;
import org.jruby.runtime.marshal.UnmarshalStream;
import org.jruby.util.ArraySupport;
import org.jruby.util.TypeConverter;

import java.io.IOException;
import java.lang.reflect.Array;
Expand Down Expand Up @@ -875,6 +876,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 ) {
Expand Down Expand Up @@ -1261,4 +1268,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
Expand Up @@ -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
Expand Down

0 comments on commit 5f7e117

Please sign in to comment.