summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-12 06:32:21 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-12 06:32:21 +0000
commit31f4a829421d2c5ecc21f42d14f5b38ac9e846de (patch)
treeedd4d2ba2ea72a245660cf409c868556a6809c98 /class.c
parentc00428ed9ec5f54c6245642650c8d7c463607248 (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 'class.c')
-rw-r--r--class.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/class.c b/class.c
index b04f00c549..93b696798d 100644
--- a/class.c
+++ b/class.c
@@ -359,26 +359,30 @@ rb_define_class(const char *name, VALUE super)
VALUE
rb_define_class_under(VALUE outer, const char *name, VALUE super)
{
+ return rb_define_class_id_under(outer, rb_intern(name), super);
+}
+
+VALUE
+rb_define_class_id_under(VALUE outer, ID id, VALUE super)
+{
VALUE klass;
- ID id;
- id = rb_intern(name);
if (rb_const_defined_at(outer, id)) {
klass = rb_const_get_at(outer, id);
if (TYPE(klass) != T_CLASS) {
- rb_raise(rb_eTypeError, "%s is not a class", name);
+ rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id));
}
if (rb_class_real(RCLASS_SUPER(klass)) != super) {
- rb_name_error(id, "%s is already defined", name);
+ rb_name_error(id, "%s is already defined", rb_id2name(id));
}
return klass;
}
if (!super) {
rb_warn("no super class for `%s::%s', Object assumed",
- rb_class2name(outer), name);
+ rb_class2name(outer), rb_id2name(id));
}
klass = rb_define_class_id(id, super);
- rb_set_class_path(klass, outer, name);
+ rb_set_class_path_string(klass, outer, rb_id2str(id));
rb_const_set(outer, id, klass);
rb_class_inherited(super, klass);
@@ -429,10 +433,14 @@ rb_define_module(const char *name)
VALUE
rb_define_module_under(VALUE outer, const char *name)
{
+ return rb_define_module_id_under(outer, rb_intern(name));
+}
+
+VALUE
+rb_define_module_under(VALUE outer, ID id)
+{
VALUE module;
- ID id;
- id = rb_intern(name);
if (rb_const_defined_at(outer, id)) {
module = rb_const_get_at(outer, id);
if (TYPE(module) == T_MODULE)