Skip to content

Commit

Permalink
* class.c, error.c, eval.c, intern.h, object.c, variable.c:
Browse files Browse the repository at this point in the history
  do not set path if it is a singleton class.  [ruby-dev:22588]
  (backport from 1.9)


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
ocean committed Jul 15, 2004
1 parent 61817f4 commit 99a04c1
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 21 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
@@ -1,3 +1,12 @@
Thu Jul 15 20:29:15 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>

* class.c, error.c, eval.c, intern.h, object.c, variable.c:
do not set path if it is a singleton class. [ruby-dev:22588]
(backport from 1.9)

variable.c (rb_set_class_path): do not set path if it is a singleton
> class. [ruby-dev:22588]

Thu Jul 15 10:15:04 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>

* ext/tk/, ext/tcltklib/: bug fix
Expand Down
24 changes: 12 additions & 12 deletions class.c
Expand Up @@ -175,7 +175,6 @@ rb_define_class_id(id, super)

if (!super) super = rb_cObject;
klass = rb_class_new(super);
rb_name_class(klass, id);
rb_make_metaclass(klass, RBASIC(super)->klass);

return klass;
Expand Down Expand Up @@ -226,6 +225,7 @@ rb_define_class(name, super)
}
klass = rb_define_class_id(id, super);
st_add_direct(rb_class_tbl, id, klass);
rb_name_class(klass, id);
rb_const_set(rb_cObject, id, klass);
rb_class_inherited(super, klass);

Expand Down Expand Up @@ -630,7 +630,7 @@ class_instance_method_list(argc, argv, mod, func)

/*
* call-seq:
* mod.instance_methods(include_super=false) => array
* mod.instance_methods(include_super=true) => array
*
* Returns an array containing the names of public instance methods in
* the receiver. For a module, these are the public methods; for a
Expand All @@ -650,8 +650,8 @@ class_instance_method_list(argc, argv, mod, func)
* end
*
* A.instance_methods #=> ["method1"]
* B.instance_methods #=> ["method2"]
* C.instance_methods #=> ["method3"]
* B.instance_methods(false) #=> ["method2"]
* C.instance_methods(false) #=> ["method3"]
* C.instance_methods(true).length #=> 43
*/

Expand All @@ -666,7 +666,7 @@ rb_class_instance_methods(argc, argv, mod)

/*
* call-seq:
* mod.protected_instance_methods(include_super=false) => array
* mod.protected_instance_methods(include_super=true) => array
*
* Returns a list of the protected instance methods defined in
* <i>mod</i>. If the optional parameter is not <code>false</code>, the
Expand All @@ -684,7 +684,7 @@ rb_class_protected_instance_methods(argc, argv, mod)

/*
* call-seq:
* mod.private_instance_methods(include_super=false) => array
* mod.private_instance_methods(include_super=true) => array
*
* Returns a list of the private instance methods defined in
* <i>mod</i>. If the optional parameter is not <code>false</code>, the
Expand All @@ -710,7 +710,7 @@ rb_class_private_instance_methods(argc, argv, mod)

/*
* call-seq:
* mod.public_instance_methods(include_super=false) => array
* mod.public_instance_methods(include_super=true) => array
*
* Returns a list of the public instance methods defined in <i>mod</i>.
* If the optional parameter is not <code>false</code>, the methods of
Expand All @@ -728,7 +728,7 @@ rb_class_public_instance_methods(argc, argv, mod)

/*
* call-seq:
* obj.singleton_methods(all=false) => array
* obj.singleton_methods(all=true) => array
*
* Returns an array of the names of singleton methods for <i>obj</i>.
* If the optional <i>all</i> parameter is true, the list will include
Expand All @@ -745,17 +745,17 @@ rb_class_public_instance_methods(argc, argv, mod)
* a = Single.new
*
* def a.one()
* end
*
* class << a
* end
* include Other
* def two()
* end
* end
*
* end
* Single.singleton_methods #=> ["four"]
* a.singleton_methods #=> ["two", "one"]
* a.singleton_methods(true) #=> ["two", "one", "three"]
* a.singleton_methods(false) #=> ["two", "one"]
* a.singleton_methods #=> ["two", "one", "three"]
*/

VALUE
Expand Down
8 changes: 4 additions & 4 deletions error.c
Expand Up @@ -400,7 +400,7 @@ exc_to_s(exc)
{
VALUE mesg = rb_attr_get(exc, rb_intern("mesg"));

if (NIL_P(mesg)) return rb_class_path(CLASS_OF(exc));
if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
if (OBJ_TAINTED(exc)) OBJ_TAINT(mesg);
return mesg;
}
Expand Down Expand Up @@ -439,11 +439,11 @@ exc_inspect(exc)
klass = CLASS_OF(exc);
exc = rb_obj_as_string(exc);
if (RSTRING(exc)->len == 0) {
return rb_str_dup(rb_class_path(klass));
return rb_str_dup(rb_class_name(klass));
}

str = rb_str_buf_new2("#<");
klass = rb_class_path(klass);
klass = rb_class_name(klass);
rb_str_buf_append(str, klass);
rb_str_buf_cat(str, ": ", 2);
rb_str_buf_append(str, exc);
Expand Down Expand Up @@ -645,7 +645,7 @@ name_err_to_s(exc)
{
VALUE mesg = rb_attr_get(exc, rb_intern("mesg")), str = mesg;

if (NIL_P(mesg)) return rb_class_path(CLASS_OF(exc));
if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
StringValue(str);
if (str != mesg) {
rb_iv_set(exc, "mesg", mesg = str);
Expand Down
2 changes: 1 addition & 1 deletion eval.c
Expand Up @@ -1142,7 +1142,7 @@ error_print()
else {
VALUE epath;

epath = rb_class_path(eclass);
epath = rb_class_name(eclass);
if (elen == 0) {
warn_print(": ");
warn_print2(RSTRING(epath)->ptr, RSTRING(epath)->len);
Expand Down
1 change: 1 addition & 0 deletions intern.h
Expand Up @@ -437,6 +437,7 @@ VALUE rb_class_path _((VALUE));
void rb_set_class_path _((VALUE, VALUE, const char*));
VALUE rb_path2class _((const char*));
void rb_name_class _((VALUE, ID));
VALUE rb_class_name _((VALUE));
void rb_autoload _((VALUE, ID, const char*));
void rb_autoload_load _((VALUE, ID));
VALUE rb_autoload_p _((VALUE, ID));
Expand Down
2 changes: 1 addition & 1 deletion object.c
Expand Up @@ -1236,7 +1236,7 @@ rb_mod_to_s(klass)

return s;
}
return rb_str_dup(rb_class_path(klass));
return rb_str_dup(rb_class_name(klass));
}

/*
Expand Down
12 changes: 9 additions & 3 deletions variable.c
Expand Up @@ -146,7 +146,6 @@ classname(klass)
{
VALUE path = Qnil;

klass = rb_class_real(klass);
if (!klass) klass = rb_cObject;
if (ROBJECT(klass)->iv_tbl) {
if (!st_lookup(ROBJECT(klass)->iv_tbl, classpath, &path)) {
Expand Down Expand Up @@ -281,11 +280,18 @@ rb_name_class(klass, id)
rb_iv_set(klass, "__classid__", ID2SYM(id));
}

VALUE
rb_class_name(klass)
VALUE klass;
{
return rb_class_path(rb_class_real(klass));
}

char *
rb_class2name(klass)
VALUE klass;
{
return RSTRING(rb_class_path(klass))->ptr;
return RSTRING(rb_class_name(klass))->ptr;
}

char *
Expand Down Expand Up @@ -1193,7 +1199,7 @@ uninitialized_constant(klass, id)
{
if (klass && klass != rb_cObject)
rb_name_error(id, "uninitialized constant %s::%s",
RSTRING(rb_class_path(klass))->ptr,
rb_class2name(klass),
rb_id2name(id));
else {
rb_name_error(id, "uninitialized constant %s", rb_id2name(id));
Expand Down

0 comments on commit 99a04c1

Please sign in to comment.