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: 9d880cf67366
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 869c5e5667aa
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Oct 11, 2016

  1. Copy the full SHA
    feba193 View commit details
  2. Copy the full SHA
    869c5e5 View commit details
Showing with 34 additions and 1 deletion.
  1. +2 −1 core/src/main/java/org/jruby/ir/IRBuilder.java
  2. +32 −0 spec/ruby/language/method_spec.rb
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
@@ -1036,7 +1036,8 @@ public Operand buildCall(CallNode callNode) {
callNode.getArgsNode() instanceof ArrayNode &&
(argsAry = (ArrayNode) callNode.getArgsNode()).size() == 1 &&
argsAry.get(0) instanceof StrNode &&
!scope.maybeUsingRefinements()) {
!scope.maybeUsingRefinements() &&
callNode.getIterNode() == null) {
StrNode keyNode = (StrNode) argsAry.get(0);
addInstr(ArrayDerefInstr.create(callResult, receiver, new FrozenString(keyNode.getValue(), keyNode.getCodeRange(), keyNode.getPosition().getFile(), keyNode.getLine())));
return callResult;
32 changes: 32 additions & 0 deletions spec/ruby/language/method_spec.rb
Original file line number Diff line number Diff line change
@@ -1235,3 +1235,35 @@ def n(value, &block)
args.should == [1, :block_value]
end
end

describe "An array-dereference method ([])" do
SpecEvaluate.desc = "for definition"

context "received the passed-in block" do
evaluate <<-ruby do
def [](*, &b)
b.call
end
ruby
pr = proc {:ok}

self[&pr].should == :ok
self['foo', &pr].should == :ok
self.[](&pr).should == :ok
self.[]('foo', &pr).should == :ok
end

evaluate <<-ruby do
def [](*)
yield
end
ruby
pr = proc {:ok}

self[&pr].should == :ok
self['foo', &pr].should == :ok
self.[](&pr).should == :ok
self.[]('foo', &pr).should == :ok
end
end
end