Content-Length: 330529 | pFad | http://github.com/jruby/jruby/commit/554704dc3855b27694ebad95b8510418f109cb28

13 Merge remote-tracking branch 'origen/jruby-9.4' · jruby/jruby@554704d · GitHub
Skip to content

Commit 554704d

Browse files
committed
Merge remote-tracking branch 'origen/jruby-9.4'
2 parents b2d7868 + d436a0e commit 554704d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

core/src/main/java/org/jruby/RubyArray.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,16 +1259,25 @@ public IRubyObject insert(IRubyObject[] args) {
12591259

12601260
@JRubyMethod(name = "insert", required = 1, rest = true, checkArity = false)
12611261
public IRubyObject insert(ThreadContext context, IRubyObject[] args) {
1262+
switch (args.length) {
1263+
case 0:
1264+
return insert();
1265+
case 1:
1266+
return insert(args[0]);
1267+
case 2:
1268+
return insert(args[0], args[1]);
1269+
}
1270+
12621271
int argc = Arity.checkArgumentCount(context, args, 1, -1);
12631272

12641273
modifyCheck(context);
12651274

1275+
long pos = RubyNumeric.num2long(args[0]);
1276+
12661277
if (argc == 1) return this;
12671278

12681279
unpack(context);
12691280

1270-
long pos = toLong(context, args[0]);
1271-
12721281
if (pos == -1) pos = realLength;
12731282
if (pos < 0) pos++;
12741283

spec/ruby/core/array/insert_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
[].insert(-2).should == []
5858
end
5959

60+
# https://bugs.ruby-lang.org/issues/13558
61+
it "attempts to coerce a lone position argument" do
62+
lambda { [].insert(Object.new) }.should raise_error(TypeError)
63+
end
64+
6065
it "tries to convert the passed position argument to an Integer using #to_int" do
6166
obj = mock('2')
6267
obj.should_receive(:to_int).and_return(2)

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/jruby/jruby/commit/554704dc3855b27694ebad95b8510418f109cb28

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy