Odd behaviour of custom "inspect" method

Can anyone explain this for me?

john@liberty:~/Work/Coding/Xronos/test$ cat testpadding.rb
class Padding

def inspect
‘.’ * 4
end

end
john@liberty:~/Work/Coding/Xronos/test$ irb -r testpadding.rb

a = Padding.new
=> …

a.inspect
=> “…”

The inspect method seems to return a string consisting of 4 full stops,
and yet irb displays six. Why? If inspect returns a string of any
other letter it seems to work as expected.

John

On Aug 13, 2008, at 14:21 , John W. wrote:

john@liberty:~/Work/Coding/Xronos/test$ irb -r testpadding.rb

a = Padding.new
=> …

a.inspect
=> “…”

wfm:

a = Padding.new
=> …

a.inspect
=> “…”

RUBY_VERSION
=> “1.8.6”

Ryan D. wrote:

On Aug 13, 2008, at 14:21 , John W. wrote:

john@liberty:~/Work/Coding/Xronos/test$ irb -r testpadding.rb

a = Padding.new
=> …

a.inspect
=> “…”

wfm:

a = Padding.new
=> …

a.inspect
=> “…”

RUBY_VERSION
=> “1.8.6”

Interesting. I had assumed it was an artefact of me using the ‘.’
symbol (something to do with regex?) but it starts to sound like an
actual bug. I’m on Ruby 1.8.7. I’ve expanded the code slightly and it
gets odder.

actually it gets extraordinarily odd. As I was preparing a transcript
to post it suddenly started working as expected - even when I use the
original files with which I tested yesterday. That’s the kind of bug I
really hate - I can’t reproduce it now, although I could when I started
to produce the transcript.

For the record, I’m running 64-bit Debian Etch with the packaged version
of Ruby 1.8.7.

John

Actually, I’ve solved it - it’s a bug in Wirble.colorize. I’ll put in a
bug report.

Cheers,
John