Search code examples
ruby-on-railsrubynewlinecontinuations

Continuing a statement on the next line WITH A COMMENT


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).


Solution

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

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