# Puts from #!, but with data structure chrome

**URL:** <https://www.ruby-forum.com/t/puts-from-but-with-data-structure-chrome/118279>\
**Category:** Ruby\
**Created:** [October 25, 2007, 11:33am UTC](https://www.ruby-forum.com/t/puts-from-but-with-data-structure-chrome/118279 "2007-10-25T11:33:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [October 25, 2007, 11:33am UTC](https://www.ruby-forum.com/t/puts-from-but-with-data-structure-chrome/118279/1 "2007-10-25T11:33:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [October 25, 2007, 11:41am UTC](https://www.ruby-forum.com/t/puts-from-but-with-data-structure-chrome/118279/2 "2007-10-25T11:41:50Z")

</div>

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.

I hope this helps

Stefano

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [October 25, 2007, 11:49am UTC](https://www.ruby-forum.com/t/puts-from-but-with-data-structure-chrome/118279/3 "2007-10-25T11:49:21Z")

</div>

Stefano C. wrote:

> Alle giovedÃ¬ 25 ottobre 2007, Greg W. ha scritto:
> 
> > 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 ?
> 
> Use p instead of puts. puts(obj) calls obj.to\_s, while p(obj) calls  
> p.inspect,  
> which is what IRB does.
> 
> I hope this helps
> 
> Stefano

Ahhh. Perfect. 🙂

– gw

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [October 25, 2007, 11:50am UTC](https://www.ruby-forum.com/t/puts-from-but-with-data-structure-chrome/118279/4 "2007-10-25T11:50:01Z")

</div>

from: Greg W. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

# 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 ?

> a  
> =\> [1, 2]

> b  
> =\> {1=\>2, 2=\>3}

> p a,b  
> [1, 2]  
> {1=\>2, 2=\>3}

> puts a.inspect, b.inspect  
> [1, 2]  
> {1=\>2, 2=\>3}

in ruby1.9, you can do

puts a.to\_s, b.to\_s

and p now returns array result (amazing) like,

> RUBY\_VERSION  
> =\> “1.9.0”

> p a,b  
> [1, 2]  
> {1=\>2, 2=\>3}  
> =\> [[1, 2], {1=\>2, 2=\>3}]

> x=(p a,b)

> p x  
> [[1, 2], {1=\>2, 2=\>3}]  
> =\> [[1, 2], {1=\>2, 2=\>3}]

nice for debugging/testing.

kind regards -botp
