unexpected #inspect behaviour
It's said in the documentation that #inspect, if not overridden should use #to_s. Instead of that, when not overridden, #inspect uses #to_s only until the first instance variable assignment, after that it is overridden by interpreter.
~$ cat > test.rb
def to_s() "instance of MyClass" end
@var = var
irb(main):001:0> load 'test.rb'
=> Instance of MyClass
Besides that #to_s stays unchanged when it's not overridden and because usually the first instance variable assignment happens in #initialize in most cases #inspect returns something like # and #to_s returns #MyClass:0x9071620
#5 Updated by matz (Yukihiro Matsumoto) almost 8 years ago
|to_s isn't inspect.
|orverride inspect if you want to change it.
But still, the behavior OP reported is weird. Redefining #to_s should
not affect inspect, if they are totally different.
I will work on.