Skip to content

Commit

Permalink
Support key swapping in Hash#transform_keys!.
Browse files Browse the repository at this point in the history
This also updates Ruby compat version to run post-2.5.1 specs for
this behavior.

https://bugs.ruby-lang.org/issues/14380
  • Loading branch information
headius committed Dec 12, 2018
1 parent 46379fe commit abe5c19
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ DO NOT MODIFIY - GENERATED CODE
<test.results.dir>${build.dir}/test-results</test.results.dir>
<tzdata.scope>provided</tzdata.scope>
<tzdata.version>2013d</tzdata.version>
<version.ruby>2.5.0</version.ruby>
<version.ruby>2.5.3</version.ruby>
<version.ruby.major>2.5</version.ruby.major>
<version.ruby.minor>0</version.ruby.minor>
<version.ruby.revision>60928</version.ruby.revision>
<version.ruby.minor>3</version.ruby.minor>
<version.ruby.revision>66309</version.ruby.revision>
</properties>
<dependencies>
<dependency>
Expand Down
12 changes: 8 additions & 4 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -1515,10 +1515,14 @@ public IRubyObject transform_values(final ThreadContext context, final Block blo
public IRubyObject transform_keys_bang(final ThreadContext context, final Block block) {
if (block.isGiven()) {
testFrozen("Hash");
RubyArray keys = keys(context);
Arrays.stream(keys.toJavaArrayMaybeUnsafe()).forEach((key) -> {
op_aset(context, block.yield(context, key), delete(context, key));
});
RubyArray pairs = (RubyArray) flatten(context);
clear();
for (int i = 0; i < pairs.size(); i += 2) {
IRubyObject key = pairs.eltOk(i);
IRubyObject newKey = block.yield(context, key);
IRubyObject value = pairs.eltOk(i + 1);
op_aset(context, newKey, value);
}
return this;
}

Expand Down
6 changes: 3 additions & 3 deletions default.build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ rake.args=
install4j.executable=/Applications/install4j7/bin/install4jc

# Ruby versions
version.ruby=2.5.0
version.ruby=2.5.3
version.ruby.major=2.5
version.ruby.minor=0
version.ruby.revision=60928
version.ruby.minor=3
version.ruby.revision=66309

0 comments on commit abe5c19

Please sign in to comment.