Hi,
In message "[ruby-talk:5658] Q's on limit/depth in dump/_dump"
on 00/10/18, Robert Feldt <feldt / ce.chalmers.se> writes:
|Some questions on the limit/aDepth in dump/_dump related to
|the following sample code:
|
|class C
| def _dump(aDepth)
| puts "depth = #{aDepth}"
| "" # Dummy
| end
|end
|#Marshal.dump([C.new],1) # => exceed depth limit (ArgumentError)
|Marshal.dump([C.new],2)
|
|bash-2.04$ ruby -v dump_depth.rb
|ruby 1.6.1 (2000-09-27) [i686-cygwin]
|depth = 0
|
|Questions:
|
|1. Why does dump(Array, limit) subtract 2 from the limit/depth?
| My guess was that it would subtract one since the object in the array
| is a sub-object to the array "one step down".
Because you're dumping array (level 1) contains an instance of C
(level 2). So you need to specify level greater than 2.
|2. If I write my own _dump functions should I subtract one or two from the
|limit when passing it on to sub-objects?
You have to subtract 1, not 2.
matz.