Joe R. MUDCRAP-CE wrote:
For general purpose file writing, does it matter whether puts or write
is used? From the docs, it seems like puts should be used for strings,
while write can be used for anything. I’m not really sure what
difference there is between the two, but the docs say something about
puts adding newlines or something.
I tend to view #puts and #print as printing methodsi, i.e. for textual
output. Note also that they accept multiple parameters.
#write on the other hand is more low level and is actually sending off
the string it gets to the underlying stream whereas #puts applies some
modifications (newline, special treatment of things that implement
Typically I use #write for stream copy operations like
File.open(“foo”, “rb”) do |in|
File.open(“bar”, “wb”) do |out|
while ( buffer = in.read( 1024 ) )
out.write( buffer )