Skip to content

Commit

Permalink
class_or_module_required
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed Jun 1, 2012
1 parent 53b61cc commit 5b95238
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
37 changes: 18 additions & 19 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5b95238

Please sign in to comment.