зеркало из https://github.com/github/ruby.git
class_or_module_required
* object.c (class_or_module_required): extract check for class or module. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
53b61ccb78
Коммит
5b95238aa7
|
@ -1,3 +1,8 @@
|
|||
Fri Jun 1 09:30:53 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* object.c (class_or_module_required): extract check for class or
|
||||
module.
|
||||
|
||||
Fri Jun 1 08:50:47 2012 Eric Hodel <drbrain@segment7.net>
|
||||
|
||||
* array.c: Updated Array documentation formatting. Patch by Zachary
|
||||
|
|
37
object.c
37
object.c
|
@ -509,6 +509,22 @@ rb_obj_inspect(VALUE obj)
|
|||
return rb_funcall(obj, rb_intern("to_s"), 0, 0);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
class_or_module_required(VALUE c)
|
||||
{
|
||||
if (SPECIAL_CONST_P(c)) goto not_class;
|
||||
switch (BUILTIN_TYPE(c)) {
|
||||
case T_MODULE:
|
||||
case T_CLASS:
|
||||
case T_ICLASS:
|
||||
break;
|
||||
|
||||
default:
|
||||
not_class:
|
||||
rb_raise(rb_eTypeError, "class or module required");
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
|
@ -530,15 +546,7 @@ rb_obj_inspect(VALUE obj)
|
|||
VALUE
|
||||
rb_obj_is_instance_of(VALUE obj, VALUE c)
|
||||
{
|
||||
switch (TYPE(c)) {
|
||||
case T_MODULE:
|
||||
case T_CLASS:
|
||||
case T_ICLASS:
|
||||
break;
|
||||
default:
|
||||
rb_raise(rb_eTypeError, "class or module required");
|
||||
}
|
||||
|
||||
c = class_or_module_required(c);
|
||||
if (rb_obj_class(obj) == c) return Qtrue;
|
||||
return Qfalse;
|
||||
}
|
||||
|
@ -577,16 +585,7 @@ rb_obj_is_kind_of(VALUE obj, VALUE c)
|
|||
{
|
||||
VALUE cl = CLASS_OF(obj);
|
||||
|
||||
switch (TYPE(c)) {
|
||||
case T_MODULE:
|
||||
case T_CLASS:
|
||||
case T_ICLASS:
|
||||
break;
|
||||
|
||||
default:
|
||||
rb_raise(rb_eTypeError, "class or module required");
|
||||
}
|
||||
|
||||
c = class_or_module_required(c);
|
||||
while (cl) {
|
||||
if (cl == c || RCLASS_M_TBL(cl) == RCLASS_M_TBL(c))
|
||||
return Qtrue;
|
||||
|
|
Загрузка…
Ссылка в новой задаче