For debugging purposes, I'd like to be able to do something like
print [1,2,3]
and have "[1,2,3]" printed to the screen, not 123. How do I go about this. I've experimented with to_s and puts, and not found anything obvious.
Thanks,
Ken
For debugging purposes, I'd like to be able to do something like
print [1,2,3]
and have "[1,2,3]" printed to the screen, not 123. How do I go about this. I've experimented with to_s and puts, and not found anything obvious.
Thanks,
Ken
Kenneth McDonald wrote:
For debugging purposes, I'd like to be able to do something like
print [1,2,3]
and have "[1,2,3]" printed to the screen, not 123. How do I go about
this. I've experimented with to_s and puts, and not found anything
obvious.Thanks,
Ken
C:\Documents and Settings\chen73>irb
irb(main):001:0> a=[1,2,3]
=> [1, 2, 3]
irb(main):002:0> p a
[1, 2, 3]
=> nil
irb(main):003:0>
Li
--
Posted via http://www.ruby-forum.com/\.
Kenneth McDonald wrote:
For debugging purposes, I'd like to be able to do something like
print [1,2,3]
and have "[1,2,3]" printed to the screen, not 123. How do I go about
this. I've experimented with to_s and puts, and not found anything
obvious.Thanks,
Ken
Each object has method inspect and it does the trick. The irb in fact
prints the result's inspect to show it to you.
["a",:b,3].inspect #=> "[\"a\", :b, 3]"
TPR.
--
Posted via http://www.ruby-forum.com/\.
p [1,2,3]
puts [1,2,3].inspect
The last is useful if you want to get the string representation of the
Ruby object, e.g. if you're using a logger, so you can do something
like:
log.debug(obj.inspect)
On Wed, Sep 24, 2008 at 12:49 AM, Kenneth McDonald <kenneth.m.mcdonald@sbcglobal.net> wrote:
For debugging purposes, I'd like to be able to do something like
print [1,2,3]
and have "[1,2,3]" printed to the screen, not 123. How do I go about this.
I've experimented with to_s and puts, and not found anything obvious.
--
普通じゃないのが当然なら答える私は何ができる?
普通でも普通じゃなくて感じるまま感じることだけをするよ!
http://stormwyrm.blogspot.com