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: b76218b2d7da
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 47d4a096dc0d
Choose a head ref
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Dec 9, 2016

  1. [ruby 2.4] Implemented Hash#transform_values(!)

    It passes the TestHash#test_transform_values and
    TestHash#test_transform_values_bang methods of the MRI test.
    herwinw committed Dec 9, 2016
    Copy the full SHA
    bd1b7d2 View commit details
  2. Merge pull request #4374 from herwinw/hash_transform_values

    [ruby 2.4] Implemented Hash#transform_values(!)
    enebo authored Dec 9, 2016
    Copy the full SHA
    47d4a09 View commit details
Showing with 25 additions and 0 deletions.
  1. +25 −0 core/src/main/java/org/jruby/RubyHash.java
25 changes: 25 additions & 0 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
@@ -1407,6 +1407,31 @@ public IRubyObject each_key(final ThreadContext context, final Block block) {
return block.isGiven() ? each_keyCommon(context, block) : enumeratorizeWithSize(context, this, "each_key", enumSizeFn());
}

@JRubyMethod(name = "transform_values")
public IRubyObject transform_values(final ThreadContext context, final Block block) {
return ((RubyHash)dup()).transform_values_bang(context, block);
}

@JRubyMethod(name = "transform_values!")
public IRubyObject transform_values_bang(final ThreadContext context, final Block block) {
if (block.isGiven()) {
testFrozen("Hash");
TransformValuesVisitor tvf = new TransformValuesVisitor();
iteratorVisitAll(context, tvf, block);
return this;
}

return enumeratorizeWithSize(context, this, "transform_values!", enumSizeFn());
}

private static class TransformValuesVisitor extends VisitorWithState<Block> {
@Override
public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, Block block) {
IRubyObject newValue = block.yield(context, value);
self.op_aset(context, key, newValue);
}
}

@JRubyMethod(name = "select!")
public IRubyObject select_bang(final ThreadContext context, final Block block) {
if (block.isGiven()) return keep_ifCommon(context, block) ? this : context.runtime.getNil();