summaryrefslogtreecommitdiff
path: root/enumerator.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-18 02:05:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-18 02:05:17 +0000
commit8a28e97ae999bf26fc59651db581ca90a9206eba (patch)
treed8940b57a9628aba53d573d7d8533bc5c0b9b679 /enumerator.c
parent6b6ca88925668a7608768740fe85978a6f3ca942 (diff)
enumerator.c: use VALUE
* enumerator.c (inspect_enumerator): use VALUE instead of mere char* by using rb_sprintf() and rb_id2str(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40805 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enumerator.c')
-rw-r--r--enumerator.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/enumerator.c b/enumerator.c
index 2464c97..a5f675e 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -880,19 +880,18 @@ static VALUE
inspect_enumerator(VALUE obj, VALUE dummy, int recur)
{
struct enumerator *e;
- const char *cname;
- VALUE eobj, str;
+ VALUE eobj, str, cname;
TypedData_Get_Struct(obj, struct enumerator, &enumerator_data_type, e);
- cname = rb_obj_classname(obj);
+ cname = rb_obj_class(obj);
if (!e || e->obj == Qundef) {
- return rb_sprintf("#<%s: uninitialized>", cname);
+ return rb_sprintf("#<%"PRIsVALUE": uninitialized>", rb_class_path(cname));
}
if (recur) {
- str = rb_sprintf("#<%s: ...>", cname);
+ str = rb_sprintf("#<%"PRIsVALUE": ...>", rb_class_path(cname));
OBJ_TAINT(str);
return str;
}
@@ -903,9 +902,7 @@ inspect_enumerator(VALUE obj, VALUE dummy, int recur)
}
/* (1..100).each_cons(2) => "#<Enumerator: 1..100:each_cons(2)>" */
- str = rb_sprintf("#<%s: ", cname);
- rb_str_append(str, rb_inspect(eobj));
- OBJ_INFECT(str, eobj);
+ str = rb_sprintf("#<%"PRIsVALUE": %+"PRIsVALUE, rb_class_path(cname), eobj);
append_method(obj, str, e->meth, e->args);
rb_str_buf_cat2(str, ">");
@@ -919,14 +916,14 @@ append_method(VALUE obj, VALUE str, ID default_method, VALUE default_args)
VALUE method, eargs;
method = rb_attr_get(obj, id_method);
- if (NIL_P(method)) {
- rb_str_buf_cat2(str, ":");
- rb_str_buf_cat2(str, rb_id2name(default_method));
- }
- else if (method != Qfalse) {
- Check_Type(method, T_SYMBOL);
+ if (method != Qfalse) {
+ ID mid = default_method;
+ if (!NIL_P(method)) {
+ Check_Type(method, T_SYMBOL);
+ mid = SYM2ID(method);
+ }
rb_str_buf_cat2(str, ":");
- rb_str_buf_cat2(str, rb_id2name(SYM2ID(method)));
+ rb_str_buf_append(str, rb_id2str(mid));
}
eargs = rb_attr_get(obj, id_arguments);
@@ -943,7 +940,7 @@ append_method(VALUE obj, VALUE str, ID default_method, VALUE default_args)
while (argc--) {
VALUE arg = *argv++;
- rb_str_concat(str, rb_inspect(arg));
+ rb_str_append(str, rb_inspect(arg));
rb_str_buf_cat2(str, argc > 0 ? ", " : ")");
OBJ_INFECT(str, arg);
}