views:

72

answers:

2

I'd like to run inspect on some object, but unfortunately it's either linking to some really big objects, or has a circular reference. That results in many pages of output.

Is there some way to limit the level of recursion that inspect is allowed to do?

A: 

No, you might want to use either prettyprint module for a 'different' visualisation (require 'pp'; pp object) or write something yourself. To write a generic dumper is quite difficult since everyone has different needs (dump binary blobs? dump strings up to which length? dump graphs with cycles? dump up to which level? ...).

Rutger Nijlunsing
A: 

I think you're going to have to change the behaviour of #inspect for your object. If you understand your objects, it shouldn't be too hard:

class Array
  def inspect
    puts "This is an array, size=#{size}"
  end
end

a = [1,2,3]

puts a.inspect #=> This is an array, size=3
Mike Woodhouse
It's an external library, so I don't know what's going on at all.
viraptor