From: "Dan Stevens (IAmAI)" Date: 2007-06-30T02:11:51+09:00 Subject: Re: Issue related to class initialization and irb > irb(main):004:0> a = Test.new > => # > irb(main):013:0> a > => # Does anyone know why the value returned by Object#object_id is different to the value returned by the 'new' method? Is one hex and the other is not? On 29/06/07, Chris Shea wrote: > On Jun 29, 10:44 am, darren kirby wrote: > > 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 > > -- > > darren kirby :: Part of the problem since 1976 ::http://badcomputer.org > > "...the number of UNIX installations has grown to 10, with more expected..." > > - Dennis Ritchie and Ken Thompson, June 1972 > > What you want to do is redefine the inspect method. > > irb(main):001:0> class Test > irb(main):002:1> attr_accessor :foo, :bar > irb(main):003:1> end > => nil > irb(main):004:0> a = Test.new > => # > irb(main):005:0> a.foo = 42 > => 42 > irb(main):006:0> a.bar = "a place to buy drinks" > => "a place to buy drinks" > irb(main):007:0> a > => # > irb(main):008:0> class Test > irb(main):009:1> def inspect > irb(main):010:2> "#" > irb(main):011:2> end > irb(main):012:1> end > => nil > irb(main):013:0> a > => # > > HTH, > Chris > > >