Bug #2658
closedrubyspec: Ruby character strings interpolates the return value of Object#inspect, without ivars, if Object#to_s does not return a String instance ERROR
Description
=begin
まつもとさん
遠藤です。
rubyspec の以下のエラーを調べてみました。
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 <top (required)>'
/home/mame/work/ruby/spec/rubyspec/language/string_spec.rb:5:in `<top (required)>'
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_smethod to generate the string. -
obj. If not overridden, uses the
to_smethod 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 mame@tsg.ne.jp
=end