which is no good cause it includes all the whitespace. I guess I can
live with
file.write “blah blah”
file.write “and so on”
but I thot I’d check and see if there is not some wierd combination of +
, / etc that would allow me to break the line, as I imagine the same
logic will apply in other ruby methods.
Thanks in advance! Ruby seems very nice, I am happy.
which is no good cause it includes all the whitespace. I guess I can
live with
file.write “blah blah”
file.write “and so on”
but I thot I’d check and see if there is not some wierd combination of +
, / etc that would allow me to break the line, as I imagine the same
logic will apply in other ruby methods.
You can do
file.write "blah blah " +
“and so on”
file.write "blah blah "
“and so on”
I myself use these rules of thumb to decide which method to use:
printing of text: puts, print, printf
output of binary or chunked data: write
E.g. for copying data from one file to another, I’d do
buffer = “”
while io1.read(1024, buffer)
io2.write buffer
end
Thanks in advance! Ruby seems very nice, I am happy.
No, just to save a little bit of typing a line with a bunch of long
object.hash[key] variables in it. But since the logic must applies to
other methods, I figured I might as well start “saving” now.
Anyway, it seems the + version works but the / ignores the next line if
the quotes are closed.
Note that for the continuation you need a bachslash "" and not a
forward slash “/”! The difference between the two variants is that
the continuation forms one long string while the plus version creates
several strings which are combined at runtime. It seems that in your
case the version with “+” may be better as you seem to pull your
strings from somewhere else (i.e. they are not constant). Can you
show the real code?
No, just to save a little bit of typing a line with a bunch of long
object.hash[key] variables in it. But since the logic must applies to
other methods, I figured I might as well start “saving” now.
Anyway, it seems the + version works but the / ignores the next line if
the quotes are closed.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.