How to p to a string

C

Carl Youngblood

Is there a way that I can cause p to store the output that it would have
sent to STDOUT into a string instead?

Thanks,
Carl Youngblood
 
W

Wejn

Hi,
what about:

irb(main):001:0> p Range.new(1,2)
1..2
nil
irb(main):002:0> puts Range.new(1,2).inspect
1..2
nil

?

Best regards,
M.
 
J

Joel VanderWerf

Carl said:
Is there a way that I can cause p to store the output that it would have
sent to STDOUT into a string instead?

Doesn't #inspect do what you want?
 
C

Carl Youngblood

Joel said:
Doesn't #inspect do what you want?
I think you're right! I'm still in the process of learning Ruby. Here
a little and there little... Thanks.
 

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

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top