From: Markus Date: 2004-09-03T04:50:34+09:00 Subject: Re: array of objects within an object > I am storing an array of objects within another object, but am not > sure how to print the values of the array out. When I do an > Port.inspect, it gives me something like this...: If you are dealing with modest sized, non-recursive structures, you can throw together something like this: class Object def pretty(indent = '') if instance_variables.length > 0 self.class.to_s+":\n"+(instance_variables.collect { |v| indent+v+': '+instance_variable_get(v).pretty(indent+' ') }.join("\n")) else self.class.to_s end end end class Numeric def pretty(indent = '') to_s end end class String def pretty(indent = '') inspect end end class Array def pretty(indent = '') super + "[\n"+ collect{ |v| ' '+indent+v.pretty(indent+' ') }.join(",\n") + "\n"+ " " + indent+"]" end end class My_class attr_accessor :test,:aa def initialize @test = "goo" @aa = [nil,true,8] end end print ["test",7,My_class.new].pretty,"\n" Not "production quality" but quick & easy for debugging purposes, and easy to extend (and, to some extent, self-extending). -- MarkusQ