# Odd behaviour of custom "inspect" method

**URL:** <https://www.ruby-forum.com/t/odd-behaviour-of-custom-inspect-method/145789>\
**Category:** Ruby\
**Created:** [August 13, 2008, 11:24pm UTC](https://www.ruby-forum.com/t/odd-behaviour-of-custom-inspect-method/145789 "2008-08-13T23:24:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [August 13, 2008, 11:24pm UTC](https://www.ruby-forum.com/t/odd-behaviour-of-custom-inspect-method/145789/1 "2008-08-13T23:24:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [August 14, 2008, 1:53am UTC](https://www.ruby-forum.com/t/odd-behaviour-of-custom-inspect-method/145789/2 "2008-08-14T01:53:12Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [August 14, 2008, 7:40am UTC](https://www.ruby-forum.com/t/odd-behaviour-of-custom-inspect-method/145789/3 "2008-08-14T07:40:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![princenamor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c0e974/32.png) [@princenamor](https://www.ruby-forum.com/u/princenamor)\
**Post date:** [August 14, 2008, 8:00am UTC](https://www.ruby-forum.com/t/odd-behaviour-of-custom-inspect-method/145789/4 "2008-08-14T08:00:33Z")

</div>

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

Cheers,  
John
