Skip to content

Commit

Permalink
Match type checks for Array#insert from MRI.
Browse files Browse the repository at this point in the history
headius committed Oct 18, 2017
1 parent a708b16 commit a3c4238
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -1047,6 +1047,9 @@ public IRubyObject insert() {
public IRubyObject insert(IRubyObject arg) {
modifyCheck();

// for type check
RubyNumeric.num2long(arg);

return this;
}

@@ -1078,12 +1081,12 @@ public IRubyObject insert19(IRubyObject arg1, IRubyObject arg2) {
public IRubyObject insert(IRubyObject[] args) {
modifyCheck();

long pos = RubyNumeric.num2long(args[0]);

if (args.length == 1) return this;

unpack();

long pos = RubyNumeric.num2long(args[0]);

if (pos == -1) pos = realLength;
if (pos < 0) pos++;

0 comments on commit a3c4238

Please sign in to comment.