Posterous theme by Cory Watilo

Output multiple lines in one Ruby puts statement via @andycroll

Output multiple lines in one puts statement

Did you know, you can print multiple lines of output in a single puts statement?

puts "This", "is", "a", "test"

This
is
a
test
=> nil

puts in the Ruby API.

Didn't know about this. Useful

Posted by

| Viewed
times | Favorited 0 times

2 Comments

Jun 20, 2010
jasonong said...
These days I like to use p instead.

p @puts, "with", _inspect

Jun 20, 2010
Arun Thampi said...
Ah ok nice, and just found out `p` automatically calls inspect on every object instead of to_s which is very useful, thanks!

Leave a comment...