aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--enumerator.c29
-rw-r--r--test/ruby/test_enumerator.rb8
3 files changed, 25 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index 77041a0fce..b687f9f94c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
-Sat May 18 11:03:05 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Sat May 18 11:05:14 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * enumerator.c (inspect_enumerator): use VALUE instead of mere char*
+ by using rb_sprintf() and rb_id2str().
* enumerator.c (append_method): extract from inspect_enumerator().
diff --git a/enumerator.c b/enumerator.c
index 2464c97c5f..a5f675e8ef 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);
}
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb
index 40dddc066d..69032fc96b 100644
--- a/test/ruby/test_enumerator.rb
+++ b/test/ruby/test_enumerator.rb
@@ -391,6 +391,14 @@ class TestEnumerator < Test::Unit::TestCase
assert_warning("", bug6214) { [].lazy.inspect }
end
+ def test_inspect_encoding
+ c = Class.new{define_method("\u{3042}"){}}
+ e = c.new.enum_for("\u{3042}")
+ s = assert_nothing_raised(Encoding::CompatibilityError) {break e.inspect}
+ assert_equal(Encoding::UTF_8, s.encoding)
+ assert_match(/\A#<Enumerator: .*:\u{3042}>\z/, s)
+ end
+
def test_generator
# note: Enumerator::Generator is a class just for internal
g = Enumerator::Generator.new {|y| y << 1 << 2 << 3; :foo }