When playing with small scripts and using puts to output some results, I
find it rather disappointing that outputting an array or hash does not
have the data structure chrome of [ ] and { } – I know IRB does this,
but I’m testing stuff too cumbersome for IRB.
Is there a way to run a #! script and cause output using puts (or
alternative) to actually show an array like [‘a’, ‘b’] instead of just
ab ?
Alle giovedì 25 ottobre 2007, Greg W. ha scritto:
When playing with small scripts and using puts to output some results, I
find it rather disappointing that outputting an array or hash does not
have the data structure chrome of [ ] and { } – I know IRB does this,
but I’m testing stuff too cumbersome for IRB.
Is there a way to run a #! script and cause output using puts (or
alternative) to actually show an array like [‘a’, ‘b’] instead of just
ab ?
– gw
Use p instead of puts. puts(obj) calls obj.to_s, while p(obj) calls
p.inspect,
which is what IRB does.