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

Commits on Jan 8, 2018

  1. Implement Hash#slice method

    for Ruby 2.5 support as in https://bugs.ruby-lang.org/issues/8499 stated.
     #4876
    ChrisBr committed Jan 8, 2018

    Unverified

    The committer email address is not verified.
    Copy the full SHA
    cfae4b2 View commit details
  2. Merge pull request #4949 from ChrisBr/feature/array-slice

    Implement Hash#slice method
    enebo authored Jan 8, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fefd7fa View commit details
Showing with 17 additions and 0 deletions.
  1. +17 −0 core/src/main/java/org/jruby/RubyHash.java
17 changes: 17 additions & 0 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
@@ -1644,6 +1644,23 @@ public IRubyObject select(final ThreadContext context, final Block block) {
return result;
}


/** rb_hash_slice
*
*/
@JRubyMethod(name = "slice", rest = true)
public RubyHash slice(final ThreadContext context, final IRubyObject[] args) {
RubyHash result = newHash(context.runtime);

for (int i = 0; i < args.length; i++) {
IRubyObject key = args[i];
IRubyObject value = this.internalGet(key);
if (value != null) result.op_aset(key, value);
}

return result;
}

private static class SelectVisitor extends VisitorWithState<Block> {
final RubyHash result;
SelectVisitor(RubyHash result) {