Continuing a statement on the next line WITH A COMMENT

Bryan Locke picture Bryan Locke · Feb 24, 2009 · Viewed 10.1k times · Source

If I have a statement in Ruby that I want to continue on the next line, normally I would add a backslash at the end of the line like this:

print x \
+ y

But if I have comments on the line, it doesn't work:

print x #show x 
+ y # show y

Is there a way around this?

(Edit: Squeegy's solution is correct and, actually, I knew you could do that but I was wondering particularly whether there is a way to have a comment on the same line as the backslash).

Answer

Alex Wayne picture Alex Wayne · Feb 25, 2009

You need to plus sign on the first line. I dont think comments work with the blackslash

puts 'abc' + #Start abc
  'def'      #Add def