summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-06 17:15:15 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-06 17:15:15 +0000
commitc2dc0dc1ce7ae4340966118994e04d4dd3fb0c3f (patch)
treeff731793b5d71c55c493e9780c24843752abeb12 /numeric.c
parentfaed90d814d6739cc55e6f0103fdc06fc1c5de0a (diff)
* numeric.c (int_upto, int_downto): Support for Integer#{down|up}to.size
[Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/numeric.c b/numeric.c
index e62cb443b9..fbec4d1768 100644
--- a/numeric.c
+++ b/numeric.c
@@ -3380,6 +3380,11 @@ fix_size(VALUE fix)
return INT2FIX(sizeof(long));
}
+static VALUE
+int_upto_size(VALUE from, VALUE args) {
+ return num_interval_step_size(from, RARRAY_PTR(args)[0], INT2FIX(1), FALSE);
+}
+
/*
* call-seq:
* int.upto(limit) {|i| block } -> self
@@ -3400,7 +3405,7 @@ fix_size(VALUE fix)
static VALUE
int_upto(VALUE from, VALUE to)
{
- RETURN_ENUMERATOR(from, 1, &to);
+ RETURN_SIZED_ENUMERATOR(from, 1, &to, int_upto_size);
if (FIXNUM_P(from) && FIXNUM_P(to)) {
long i, end;
@@ -3421,6 +3426,11 @@ int_upto(VALUE from, VALUE to)
return from;
}
+static VALUE
+int_downto_size(VALUE from, VALUE args) {
+ return num_interval_step_size(from, RARRAY_PTR(args)[0], INT2FIX(-1), FALSE);
+}
+
/*
* call-seq:
* int.downto(limit) {|i| block } -> self
@@ -3442,7 +3452,7 @@ int_upto(VALUE from, VALUE to)
static VALUE
int_downto(VALUE from, VALUE to)
{
- RETURN_ENUMERATOR(from, 1, &to);
+ RETURN_SIZED_ENUMERATOR(from, 1, &to, int_downto_size);
if (FIXNUM_P(from) && FIXNUM_P(to)) {
long i, end;