From: Stefano Crocco Date: 2007-06-30T01:57:05+09:00 Subject: Re: Issue related to class initialization and irb Alle venerd� 29 giugno 2007, darren kirby ha scritto: > Hello all, > > My class is a library that allows users to read information/tags etc from > Flac files. > > When the class is initialized in irb the content of every single instance > variable is dumped to the console. This library parses a lot of data from > various blocks, and has many data structures to hold it all. As such, this > output can contain as much as two screens worth. Some of this data is > non-readable and is for 'top-secret internal use only'. That is, it isn't > secret, but it has no value or use to the user directly ;). > > Anyway, I would really like to clean up this output and have irb print only > eg: > > => # > > Or perhaps the above with a brief enumeration of the blocks found and their > sizes and/or offsets. To this end I tried defining the class' to_s method, > and modifying the initialize method's return value. Neither had an effect. > How might I accomplish this? > > Thanks for consideration, > -d I think you should redefine the inspect method: irb: 006> class C irb: 007+> def initialize x irb: 008+> @x = x irb: 009+> end irb: 010+> def inspect irb: 011+> "C: x=#{@x}" irb: 012+> end irb: 013+> end irb: 015> C.new 2 => C: x2 I hope this helps Stefano