Odd behaviour of custom "inspect" method

J

John Winters

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
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
 
R

Ryan Davis

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
=> "...."
wfm:
=> "1.8.6"
 
J

John Winters

Ryan said:
=> "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
 
J

John Winters

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

Cheers,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,055
Members
47,659
Latest member
salragu

Latest Threads

Top