[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: How to write ruby in multiple lines

seebs

5/9/2007 6:09:00 PM

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

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

1 Answer

james.d.masters

5/9/2007 6:16:00 PM

0

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

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