How to write ruby in multiple lines

All,

How can I write “s = s1 + s2 + s3” in multiple lines like below:

s= s1

  • s2
  • s3

Thanks

In message [email protected], anakintang
writes:

How can I write “s = s1 + s2 + s3” in multiple lines like below:

s= s1

  • s2
  • s3

You can’t.

You can do it differently, though:

s = s1 +
s2 +
s3

If you have an operator at the end of the line, needing operands, Ruby
keeps reading.

-s

On Wednesday 09 May 2007, anakintang wrote:

All,

How can I write “s = s1 + s2 + s3” in multiple lines like below:

s= s1

  • s2
  • s3

Thanks

Like that
s = s1 +
s2 +
s3

or

s = s1
+ s2
+ s3

AFAIK, the first form is more in use than the second.

anakintang schrieb:

How can I write “s = s1 + s2 + s3” in multiple lines like below:

s= s1
+ s2
+ s3

Regards,
Pit

On May 9, 11:08 am, [email protected] (Peter S.) wrote:

s = s1 +
s2 +
s3

If you have an operator at the end of the line, needing operands, Ruby
keeps reading.

-s

You actually can with a trailing backslash:

% irb
irb(main):001:0> s1 = s2 = s3 = 1
=> 1
irb(main):002:0> s = s1
irb(main):003:0* + s2
irb(main):004:0* + s3
=> 3

On 05/09/2007 11:19 AM, Sylvain J. wrote:

s = s1
+ s2
+ s3

AFAIK, the first form is more in use than the second.

In the example given, which is obviously contrived, it makes
little difference. But when s1, s2, and s3 are longer
expressions, I find that the second version is more readily
grokked.

Without looking at the end of a line, you can tell that it is a
continuation of a previous line, and while at the end of a line
to can tell that it is continued.

That’s my $0.02

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs