summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-28 02:18:58 (GMT)
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-28 02:18:58 (GMT)
commit85f192b075943b974ce87fcc63d612c0bd9bb337 (patch)
tree4405ab971c9ae6a899c12cbb6eb121197fd4544b /range.c
parentb7d6367979d52b6506dee97c6750f88a7adb6e16 (diff)
range.c: Add Range#%
[Feature #14697] [ruby-core:86588] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/range.c b/range.c
index d781af3..297303b 100644
--- a/range.c
+++ b/range.c
@@ -497,6 +497,12 @@ range_step(int argc, VALUE *argv, VALUE range)
return range;
}
+static VALUE
+range_percent_step(VALUE range, VALUE step)
+{
+ return range_step(1, &step, range);
+}
+
#if SIZEOF_DOUBLE == 8 && defined(HAVE_INT64_T)
union int64_double {
int64_t i;
@@ -1549,6 +1555,7 @@ Init_Range(void)
rb_define_method(rb_cRange, "hash", range_hash, 0);
rb_define_method(rb_cRange, "each", range_each, 0);
rb_define_method(rb_cRange, "step", range_step, -1);
+ rb_define_method(rb_cRange, "%", range_percent_step, 1);
rb_define_method(rb_cRange, "bsearch", range_bsearch, 0);
rb_define_method(rb_cRange, "begin", range_begin, 0);
rb_define_method(rb_cRange, "end", range_end, 0);