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

···

--
Posted via http://www.ruby-forum.com/.

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

···

In message <f12329bb77e7a3fa17dc936713d87dca@ruby-forum.com>, anakintang writes:

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

s= s1
  + s2
  + s3

Like that
s = s1 +
    s2 +
    s3

or

s = s1 \
    + s2 \
    + s3

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

···

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

--
Sylvain Joyeux

anakintang schrieb:

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

   s= s1 \
      + s2 \
      + s3

Regards,
Pit

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 May 9, 11:08 am, s...@seebs.net (Peter Seebach) wrote:

In message <f12329bb77e7a3fa17dc936713d87...@ruby-forum.com>, 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

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

···

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

On Wednesday 09 May 2007, anakintang wrote:

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

Like that
s = s1 +
    s2 +
    s3

or

s = s1 \
    + s2 \
    + s3

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

--
Glen