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 | 5b1746cc000fbc0a045a7de8f64eceb6ec3228c5 (patch) | |
| tree | edd4d2ba2ea72a245660cf409c868556a6809c98 /struct.c | |
| parent | edff5cfea288c633af9f7ffc1c68dbe0699b8ded (diff) | |
| download | ruby-5b1746cc000fbc0a045a7de8f64eceb6ec3228c5.tar.gz ruby-5b1746cc000fbc0a045a7de8f64eceb6ec3228c5.tar.xz ruby-5b1746cc000fbc0a045a7de8f64eceb6ec3228c5.zip | |
* 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: http://svn.ruby-lang.org/repos/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)) { |
