[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Odd behaviour of custom "inspect" method

John Winters

8/13/2008 9:22:00 PM

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
--
Posted via http://www.ruby-....

3 Answers

Ryan Davis

8/13/2008 11:50:00 PM

0


On Aug 13, 2008, at 14:21 , John Winters wrote:

> 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
> => "...."

wfm:

>> a = Padding.new
=> ....
>> a.inspect
=> "...."
>> RUBY_VERSION
=> "1.8.6"




John Winters

8/14/2008 5:37:00 AM

0

Ryan Davis wrote:
> On Aug 13, 2008, at 14:21 , John Winters 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
--
Posted via http://www.ruby-....

John Winters

8/14/2008 5:58:00 AM

0

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

Cheers,
John
--
Posted via http://www.ruby-....