ruby - How do I concatenate a string in a while loop? -


i want read lines in loop , concatenate them:

d = "" while s = gets   d = d.concat(s) end puts d 

after cancel loop cntrl+z (on windows), output last string read in loop. tried + , << same result.

you can in two ways way:

d = "" while s = gets   d << s end puts d 

edit: marc-andré lafortune noticed using += not idea, leave << method here.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -