summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-06 17:15:30 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-06 17:15:30 +0000
commit3a4eb4dd39b4a6687068de391c8543008c3f977c (patch)
tree0bbaca48523124f4815108648916f2676f4e18dd /numeric.c
parentc2dc0dc1ce7ae4340966118994e04d4dd3fb0c3f (diff)
* numeric.c (int_dotimes): Support for Integer#times.size
[Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/numeric.c b/numeric.c
index fbec4d1768..b36908a8aa 100644
--- a/numeric.c
+++ b/numeric.c
@@ -3473,6 +3473,18 @@ int_downto(VALUE from, VALUE to)
return from;
}
+static VALUE
+int_dotimes_size(VALUE num)
+{
+ if (FIXNUM_P(num)) {
+ if (NUM2LONG(num) <= 0) return INT2FIX(0);
+ }
+ else {
+ if (RTEST(rb_funcall(num, '<', 1, INT2FIX(0)))) return INT2FIX(0);
+ }
+ return num;
+}
+
/*
* call-seq:
* int.times {|i| block } -> self
@@ -3495,7 +3507,7 @@ int_downto(VALUE from, VALUE to)
static VALUE
int_dotimes(VALUE num)
{
- RETURN_ENUMERATOR(num, 0, 0);
+ RETURN_SIZED_ENUMERATOR(num, 0, 0, int_dotimes_size);
if (FIXNUM_P(num)) {
long i, end;