diff options
author | Nobuyoshi Nakada <[email protected]> | 2023-03-21 22:46:05 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2023-04-14 10:22:09 +0900 |
commit | 1a149aab776aa6741628eb35482eff1ded197fd2 () | |
tree | c8c325d96a25e722f6dc5f11d74ea6994389eaae /range.c | |
parent | 8286eed20bbc88ed607dfc38b6e0439934671a45 (diff) |
Extract range type check functions
Notes: Merged: https://.com/ruby/ruby/pull/7574
-rw-r--r-- | range.c | 55 |
1 files changed, 36 insertions, 19 deletions
@@ -1769,6 +1769,35 @@ range_include(VALUE range, VALUE val) return rb_call_super(1, &val); } static VALUE range_string_cover_internal(VALUE range, VALUE val) { @@ -1777,13 +1806,11 @@ range_string_cover_internal(VALUE range, VALUE val) int nv = FIXNUM_P(beg) || FIXNUM_P(end) || linear_object_p(beg) || linear_object_p(end); - if (nv || - !NIL_P(rb_check_to_integer(beg, "to_int")) || - !NIL_P(rb_check_to_integer(end, "to_int"))) { return r_cover_p(range, beg, end, val); } - else if (RB_TYPE_P(beg, T_STRING) || RB_TYPE_P(end, T_STRING)) { - if (RB_TYPE_P(beg, T_STRING) && RB_TYPE_P(end, T_STRING)) { return r_cover_p(range, beg, end, val); } if (NIL_P(beg)) { @@ -1801,11 +1828,7 @@ range_string_cover_internal(VALUE range, VALUE val) } } - if (NIL_P(beg) || NIL_P(end)) { - rb_raise(rb_eTypeError, "cannot determine inclusion in beginless/endless ranges"); - } - - return Qundef; } static VALUE @@ -1816,20 +1839,14 @@ range_include_internal(VALUE range, VALUE val) int nv = FIXNUM_P(beg) || FIXNUM_P(end) || linear_object_p(beg) || linear_object_p(end); - if (nv || - !NIL_P(rb_check_to_integer(beg, "to_int")) || - !NIL_P(rb_check_to_integer(end, "to_int"))) { return r_cover_p(range, beg, end, val); } - else if (RB_TYPE_P(beg, T_STRING) && RB_TYPE_P(end, T_STRING)) { return rb_str_include_range_p(beg, end, val, RANGE_EXCL(range)); } - if (NIL_P(beg) || NIL_P(end)) { - rb_raise(rb_eTypeError, "cannot determine inclusion in beginless/endless ranges"); - } - - return Qundef; } static int r_cover_range_p(VALUE range, VALUE beg, VALUE end, VALUE val); |