diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-08-12 06:32:21 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-08-12 06:32:21 +0000 |
commit | 31f4a829421d2c5ecc21f42d14f5b38ac9e846de (patch) | |
tree | edd4d2ba2ea72a245660cf409c868556a6809c98 /struct.c | |
parent | c00428ed9ec5f54c6245642650c8d7c463607248 (diff) |
* class.c (rb_define_class_id_under, rb_define_module_id_under):
new functions to define a nested class/module with non-ascii
name.
* struct.c (make_struct): use name with encoding.
* struct.c (inspect_struct): ditto. [ruby-core:24849]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'struct.c')
-rw-r--r-- | struct.c | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -196,7 +196,7 @@ make_struct(VALUE name, VALUE members, VALUE klass) rb_warn("redefining constant Struct::%s", StringValuePtr(name)); rb_mod_remove_const(klass, ID2SYM(id)); } - nstr = rb_define_class_under(klass, rb_id2name(id), klass); + nstr = rb_define_class_id_under(klass, id, klass); } rb_ivar_set(nstr, id_members, members); @@ -496,21 +496,19 @@ rb_struct_each_pair(VALUE s) static VALUE inspect_struct(VALUE s, VALUE dummy, int recur) { - const char *cname = rb_class2name(rb_obj_class(s)); - VALUE str, members; + VALUE cname = rb_class_name(rb_obj_class(s)); + VALUE members, str = rb_str_new2("#<struct "); long i; + char first = RSTRING_PTR(cname)[0]; + if (recur || first != '#') { + rb_str_append(str, cname); + } if (recur) { - return rb_sprintf("#<struct %s:...>", cname); + return rb_str_cat2(str, ":...>"); } members = rb_struct_members(s); - if (cname[0] == '#') { - str = rb_str_new2("#<struct "); - } - else { - str = rb_sprintf("#<struct %s ", cname); - } for (i=0; i<RSTRUCT_LEN(s); i++) { VALUE slot; ID id; @@ -518,6 +516,9 @@ inspect_struct(VALUE s, VALUE dummy, int recur) if (i > 0) { rb_str_cat2(str, ", "); } + else if (first != '#') { + rb_str_cat2(str, " "); + } slot = RARRAY_PTR(members)[i]; id = SYM2ID(slot); if (rb_is_local_id(id) || rb_is_const_id(id)) { |