Permalink
Browse files

Array#{rotate, rotate!} raises a TypeError if not passed an integer a…

…rgument
  • Loading branch information...
Watson1978 committed Jul 18, 2012
1 parent 7a854cb commit f66a573c2c90188aeaab9fffff42675a09c79fdf
Showing with 9 additions and 10 deletions.
  1. +9 −8 array.c
  2. +0 −2 spec/frozen/tags/macruby/core/array/rotate_tags.txt
View
17 array.c
@@ -1396,13 +1396,14 @@ ary_rotate(VALUE ary, long cnt)
VALUE
rary_rotate_bang(VALUE ary, SEL sel, int argc, VALUE *argv)
{
- VALUE n;
long cnt = 1;
- rb_scan_args(argc, argv, "01", &n);
- if (!NIL_P(n)) {
- cnt = NUM2LONG(n);
+ switch (argc) {
+ case 1: cnt = NUM2LONG(argv[0]);
+ case 0: break;
+ default: rb_scan_args(argc, argv, "01", NULL);
}
+
rb_ary_modify(ary);
ary_rotate(ary, cnt);
return ary;
@@ -1427,12 +1428,12 @@ VALUE
rary_rotate(VALUE ary, SEL sel, int argc, VALUE *argv)
{
VALUE rotated;
- VALUE n;
long cnt = 1;
- rb_scan_args(argc, argv, "01", &n);
- if (!NIL_P(n)) {
- cnt = NUM2LONG(n);
+ switch (argc) {
+ case 1: cnt = NUM2LONG(argv[0]);
+ case 0: break;
+ default: rb_scan_args(argc, argv, "01", NULL);
}
rotated = rb_ary_dup(ary);
@@ -1,2 +0,0 @@
-fails:Array#rotate with an argument n raises a TypeError if not passed an integer-like argument
-fails:Array#rotate! with an argument n raises a TypeError if not passed an integer-like argument

0 comments on commit f66a573

Please sign in to comment.