summaryrefslogtreecommitdiff
path: root/enumerator.c
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-12 06:39:58 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-12 06:39:58 +0000
commit914a290324016b4f0b9a6080e334658cb3bf9f37 (patch)
treeee20461f20e0d22829d1be89cf9bf8ddb6215d91 /enumerator.c
parent3a637971a2a5939c7306ed7f9acd89689f37f25b (diff)
enumerator.c: rb_arithmetic_sequence_extract
New public C-API for extracting components of Enumerator::ArithmeticSequence or Range. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enumerator.c')
-rw-r--r--enumerator.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/enumerator.c b/enumerator.c
index 615f933..4365410 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -2777,6 +2777,27 @@ arith_seq_exclude_end_p(VALUE self)
return RTEST(arith_seq_exclude_end(self));
}
+int
+rb_arithmetic_sequence_extract(VALUE obj, VALUE *begin, VALUE *end, VALUE *step, int *exclude_end)
+{
+ if (rb_obj_is_kind_of(obj, rb_cArithSeq)) {
+ *begin = arith_seq_begin(obj);
+ *end = arith_seq_end(obj);
+ *step = arith_seq_step(obj);
+ *exclude_end = arith_seq_exclude_end_p(obj);
+ return 1;
+ }
+ else if (rb_obj_is_kind_of(obj, rb_cRange)) {
+ *begin = RANGE_BEG(obj);
+ *end = RANGE_END(obj);
+ *step = INT2FIX(1);
+ *exclude_end = RTEST(RANGE_EXCL(obj));
+ return 1;
+ }
+
+ return 0;
+}
+
/*
* call-seq:
* aseq.first -> num or nil