puts from #!, but with data structure chrome

G

Greg Willits

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
 
S

Stefano Crocco

Alle gioved=C3=AC 25 ottobre 2007, Greg Willits 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.inspe=
ct,=20
which is what IRB does.

I hope this helps

Stefano
 
P

Peña, Botp

ZnJvbTogR3JlZyBXaWxsaXRzIFttYWlsdG86bGlzdHNAZ3JlZ3dpbGxpdHMud3NdIA0KIyBJcyB0
aGVyZSBhIHdheSB0byBydW4gYSAjISBzY3JpcHQgYW5kIGNhdXNlIG91dHB1dCB1c2luZyBwdXRz
IChvcg0KIyBhbHRlcm5hdGl2ZSkgdG8gYWN0dWFsbHkgc2hvdyBhbiBhcnJheSBsaWtlIFsnYScs
ICdiJ10gaW5zdGVhZCBvZiBqdXN0DQojIGFiID8NCg0KPiBhDQo9PiBbMSwgMl0NCg0KPiBiDQo9
PiB7MT0+MiwgMj0+M30NCg0KPiBwIGEsYg0KWzEsIDJdDQp7MT0+MiwgMj0+M30NCg0KPiBwdXRz
IGEuaW5zcGVjdCwgYi5pbnNwZWN0DQpbMSwgMl0NCnsxPT4yLCAyPT4zfQ0KDQoNCmluIHJ1Ynkx
LjksIHlvdSBjYW4gZG8gDQoNCnB1dHMgYS50b19zLCBiLnRvX3MNCg0KYW5kIHAgbm93IHJldHVy
bnMgYXJyYXkgcmVzdWx0IChhbWF6aW5nKSBsaWtlLA0KDQo+IFJVQllfVkVSU0lPTg0KPT4gIjEu
OS4wIg0KDQo+IHAgYSxiDQpbMSwgMl0NCnsxPT4yLCAyPT4zfQ0KPT4gW1sxLCAyXSwgezE9PjIs
IDI9PjN9XQ0KDQo+IHg9KHAgYSxiKQ0KDQo+IHAgeA0KW1sxLCAyXSwgezE9PjIsIDI9PjN9XQ0K
PT4gW1sxLCAyXSwgezE9PjIsIDI9PjN9XQ0KDQpuaWNlIGZvciBkZWJ1Z2dpbmcvdGVzdGluZy4N
Cg0Ka2luZCByZWdhcmRzIC1ib3RwDQo=
 
G

Greg Willits

Stefano said:
Alle giovedì 25 ottobre 2007, Greg Willits 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top