From 197536164f3e9258ed69dce2c2e26ff43fa8f89c Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 15 Feb 2008 15:21:51 +0000 Subject: * range.c (rb_range_beg_len): check if responds to "begin" and "end" methods for non-Range object. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- range.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'range.c') diff --git a/range.c b/range.c index b72a4531f..e3dd44290 100644 --- a/range.c +++ b/range.c @@ -597,12 +597,10 @@ rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err) excl = EXCL(range); } else { - b = rb_check_to_integer(range, "begin"); - if (NIL_P(b)) - return Qfalse; - e = rb_check_to_integer(range, "end"); - if (NIL_P(e)) - return Qfalse; + if (!rb_respond_to(range, id_beg)) return Qfalse; + if (!rb_respond_to(range, id_end)) return Qfalse; + b = rb_funcall(range, id_beg, 0); + e = rb_funcall(range, id_end, 0); excl = RTEST(rb_funcall(range, rb_intern("exclude_end?"), 0)); } beg = NUM2LONG(b); @@ -751,8 +749,6 @@ range_include(VALUE range, VALUE val) } else if (TYPE(beg) == T_STRING && TYPE(end) == T_STRING && RSTRING_LEN(beg) == 1 && RSTRING_LEN(end) == 1) { - rb_encoding *enc = rb_enc_check(beg, end); - if (NIL_P(val)) return Qfalse; if (TYPE(val) == T_STRING) { if (RSTRING_LEN(val) == 0 || RSTRING_LEN(val) > 1) -- cgit