From: Robert Klemme Date: 2006-09-20T22:45:07+09:00 Subject: Re: The default array print format On 20.09.2006 15:07, Bart Braem wrote: > Hello, > > I was playing around with some LDAP results in a Rails system and it did not > work at all, I kept getting strang --- and - in the results. It turned out > I did not index the array properly and I was converting it to strings... > Another thing I noticed lately is that when I try to print arrays they don't > look as good as in say PHP. > Now I wonder: isn't it possible to make array print nicer and clearer by > default? I know there is a pretty print package, but why stick to a less > clear default implementation? > Just wondering of course... Did you probably miss one of the standard methods available? >> a=%w{foo bar baz} => ["foo", "bar", "baz"] >> puts a foo bar baz => nil >> p a ["foo", "bar", "baz"] => nil >> puts a.to_s foobarbaz => nil >> puts a.inspect ["foo", "bar", "baz"] => nil Granted, the version using to_s is certainly questionable but the other two alternatives (especially p, which uses #inspect internally) are pretty clear, aren't they? Kind regards robert