From: Dossy Date: 2003-01-04T05:58:49+09:00 Subject: Re: dump depth argument On 2003.01.04, Tom Sawyer wrote: > On Friday 03 January 2003 12:05 pm, Dossy wrote: > > $ ri Marshal#dump [...] > > Dossy, > > you crack me up. i've read this! that's what i don't understand. according to > it, anIO is optional but when i try the second example it bombs. not very > optional. maybe i just don't know how to read this correctly but it seems to > be acting more like: > > dump( anObject [, anIO [, limit=1 ] ] ) > > what am i missing? irb(main):007:0> class Foo irb(main):008:1> def initialize(x) irb(main):009:2> @foo = x irb(main):010:2> end irb(main):011:1> end nil irb(main):012:0> class Bar irb(main):013:1> def initialize(x) irb(main):014:2> @bar = x irb(main):015:2> end irb(main):016:1> end nil irb(main):017:0> foo = Foo.new(Bar.new("baz")) #> irb(main):018:0> Marshal.dump(foo) "\004\006o:\010Foo\006:\t@fooo:\010Bar\006:\t@bar\"\010baz" irb(main):032:0> Marshal.dump(foo, 2) ArgumentError: exceed depth limit from (irb):32:in `dump' from (irb):32 While the limit would be more useful if it weren't a hard limit but instead a suggested limit, it does behave as documented, IMHO. rb(main):090:0> rdio, wrio = IO.pipe [#, #] irb(main):091:0> Marshal.dump(foo, wrio, 3); wrio.print "\n"; wrio.flush # irb(main):092:0> rdio.readline "\004\006o:\010Foo\006:\t@fooo:\010Bar\006:\t@bar\"\010baz\n" As I said, it'd be more interesting if the limit parameter to Marshal#dump simply stopped the recursive traversal of child objects at limit, instead of throwing an error ... but, I'm not the language implementer, so it's not my call to make ... -- Dossy -- Dossy Shiobara mail: dossy@panoptic.com Panoptic Computer Network web: http://www.panoptic.com/ "He realized the fastest way to change is to laugh at your own folly -- then you can let go and quickly move on." (p. 70)