| 1 |
#include "ruby/ruby.h" |
| 2 |
|
| 3 |
static VALUE |
| 4 |
arith_seq_s_extract(VALUE mod, VALUE obj) |
| 5 |
{ |
| 6 |
rb_arithmetic_sequence_components_t x; |
| 7 |
VALUE ret; |
| 8 |
int r; |
| 9 |
|
| 10 |
r = rb_arithmetic_sequence_extract(obj, &x); |
| 11 |
|
| 12 |
ret = rb_ary_new2(5); |
| 13 |
rb_ary_store(ret, 0, r ? x.begin : Qnil); |
| 14 |
rb_ary_store(ret, 1, r ? x.end : Qnil); |
| 15 |
rb_ary_store(ret, 2, r ? x.step : Qnil); |
| 16 |
rb_ary_store(ret, 3, r ? INT2FIX(x.exclude_end) : Qnil); |
| 17 |
rb_ary_store(ret, 4, INT2FIX(r)); |
| 18 |
|
| 19 |
return ret; |
| 20 |
} |
| 21 |
|
| 22 |
void |
| 23 |
Init_extract(void) |
| 24 |
{ |
| 25 |
VALUE cArithSeq = rb_path2class("Enumerator::ArithmeticSequence"); |
| 26 |
rb_define_singleton_method(cArithSeq, "__extract__", arith_seq_s_extract, 1); |
| 27 |
} |