[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to p to a string

Carl Youngblood

11/29/2003 1:56:00 AM

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

3 Answers

Wejn

11/29/2003 2:33:00 AM

0

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.
--
# Michal Safranek, email:
a=(("a".."z").to_a+["@","."]);p(("%b"%[0x645bbb83a6a496]
).scan(/...../).map{|x|a[Integer("0b"+x)]}.join.reverse)


Joel VanderWerf

11/29/2003 2:34:00 AM

0

Carl Youngblood wrote:
> 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?



Carl Youngblood

11/29/2003 5:22:00 PM

0

Joel VanderWerf wrote:
> Carl Youngblood wrote:
>
>> 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?
>
>
>
I think you're right! I'm still in the process of learning Ruby. Here
a little and there little... Thanks.