## Thu 13 Dec 2007 07:22:13 PM GMT
# just play with an array and see what you can do with it
a = `uname -a`.to_a
print a.class
puts a.class
__END__
what's the difference bewteen these two methods of printing? Both say
the same thing. Also how can I find out for myself with ri? ri IO.print
<< is that it? ri IO.puts << is that it?
Puts is defined in terms of print, and handles multiple arguments and
elements ending with a separator somewhat differently
shadowfax:~/ssanta rick$ qri io#puts
---------------------------------------------------------------- IO#puts
ios.puts(obj, ...) => nil
------------------------------------------------------------------------
Writes the given objects to ios as with IO#print. Writes a record
separator (typically a newline) after any that do not already end
with a newline sequence. If called with an array argument, writes
each element on a new line. If called without arguments, outputs a
single record separator.
$stdout.puts("this", "is", "a", "test")
produces:
this
is
a
test
shadowfax:~/ssanta rick$ qri Kernel#print
----------------------------------------------------------- Kernel#print
print(obj, ...) => nil
------------------------------------------------------------------------
Prints each object in turn to $stdout. If the output field
separator ($,) is not nil, its contents will appear between each
field. If the output record separator ($\) is not nil, it will be
appended to the output. If no arguments are given, prints $_.
Objects that aren't strings will be converted by calling their
to_s method.
print "cat", [1,2,3], 99, "\n"
$, = ", "
$\ = "\n"
print "cat", [1,2,3], 99
produces:
cat12399
cat, 1, 2, 3, 99