From: Yusuke Endoh Date: 2010-01-26T20:39:57+09:00 Subject: [ruby-dev:40162] [Bug #2658] rubyspec: Ruby character strings interpolates the return value of Object#inspect, without ivars, if Object#to_s does not return a String instance ERROR Bug #2658: rubyspec: Ruby character strings interpolates the return value of Object#inspect, without ivars, if Object#to_s does not return a String instance ERROR http://redmine.ruby-lang.org/issues/show/2658 起票者: Yusuke Endoh ステータス: Open, 優先度: Normal 担当者: Yukihiro Matsumoto, カテゴリ: core, Target version: 1.9.2 ruby -v: ruby 1.9.2dev (2010-01-26 trunk 26425) [i686-linux] まつもとさん 遠藤です。 rubyspec の以下のエラーを調べてみました。 9) Ruby character strings interpolates the return value of Object#inspect, without ivars, if Object#to_s does not return a String instance ERROR ArgumentError: wrong number of arguments(2 for 1) /home/mame/work/ruby/spec/rubyspec/language/string_spec.rb:158:in `[]' /home/mame/work/ruby/spec/rubyspec/language/string_spec.rb:158:in `block (2 levels) in ' /home/mame/work/ruby/spec/rubyspec/language/string_spec.rb:5:in `' r25428 が原因です。このコミットでは、 - rdoc の文章が壊れています。 - rdoc によると、「to_s が override されて *いない* ときは to_s を使う」 という仕様だと思いますが、現在は to_s が override されて *いる* ときに to_s を使うようになっていると思います。 $ ./ruby -ve ' class C def to_s; "overridden"; end end p C.new ' ruby 1.9.2dev (2010-01-26 trunk 26425) [i686-linux] overridden ということで、以下のパッチをコミットをしてもいいでしょうか。 このパッチによって上記の rubyspec のエラーが消えることを確認しています。 diff --git a/object.c b/object.c index 73e5bd1..441f226 100644 --- a/object.c +++ b/object.c @@ -367,8 +367,6 @@ inspect_obj(VALUE obj, VALUE str, int recur) * obj.inspect => string * * Returns a string containing a human-readable representation of - * obj. If not overridden and no instance variables, uses the - * to_s method to generate the string. * obj. If not overridden, uses the to_s method to * generate the string. * @@ -381,7 +379,7 @@ extern int rb_obj_basic_to_s_p(VALUE); static VALUE rb_obj_inspect(VALUE obj) { - if (TYPE(obj) == T_OBJECT && rb_obj_basic_to_s_p(obj)) { + if (TYPE(obj) == T_OBJECT && !rb_obj_basic_to_s_p(obj)) { int has_ivar = 0; VALUE *ptr = ROBJECT_IVPTR(obj); long len = ROBJECT_NUMIV(obj); -- Yusuke ENDOH ---------------------------------------- http://redmine.ruby-lang.org