From 795c29dcda01fa81a3ccebee4433adabe6778d76 Mon Sep 17 00:00:00 2001 From: eregon Date: Tue, 14 Aug 2012 10:20:44 +0000 Subject: Kernel#inspect: improve consistency and do not call #to_s. A class can now benefit from the nice default #inspect even if it defines #to_s. Also, there is no more unexpected change in #inspect result. Internal structures have been adapted so they don't rely on the removed behavior (#inspect calling overridden #to_s). * object.c (rb_obj_inspect): Kernel#inspect: do not call #to_s. * test/ruby/test_object.rb (test_inspect): add tests for Kernel#inspect. * bignum.c, io.c, numeric.c, object.c, proc.c, vm.c (Init_*): alias #inspect to #to_s where it was expected. [ruby-core:43238][Feature #6130] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36699 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_object.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test') diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb index 70dcd04201..61482f7c1a 100644 --- a/test/ruby/test_object.rb +++ b/test/ruby/test_object.rb @@ -690,6 +690,31 @@ class TestObject < Test::Unit::TestCase assert_equal(true, s.tainted?) end + def test_inspect + x = Object.new + assert_match(/\A#\z/, x.inspect) + + x.instance_variable_set(:@ivar, :value) + assert_match(/\A#\z/, x.inspect) + + x = Object.new + x.instance_variable_set(:@recur, x) + assert_match(/\A#>\z/, x.inspect) + + x = Object.new + x.instance_variable_set(:@foo, "value") + x.instance_variable_set(:@bar, 42) + assert_match(/\A#\z/, x.inspect) + + # #inspect does not call #to_s anymore + feature6130 = '[ruby-core:43238]' + x = Object.new + def x.to_s + "to_s" + end + assert_match(/\A#\z/, x.inspect, feature6130) + end + def test_exec_recursive Thread.current[:__recursive_key__] = nil a = [[]] -- cgit v1.2.3