[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

compact join with new line...

Josselin

9/14/2006 5:05:00 PM

I would like to compact join address elements by inserting a new line
between them

in my class address I am using

def to_s
[@street, @city, @country ].compact.join(" - ")
end

but I'd like to replace " -" by a new line character to display the
full adress on 3 lines

is it possible ?

joss



2 Answers

Farrel Lifson

9/14/2006 5:14:00 PM

0

On 14/09/06, Josselin <josselin@wanadoo.fr> wrote:
> I would like to compact join address elements by inserting a new line
> between them
>
> in my class address I am using
>
> def to_s
> [@street, @city, @country ].compact.join(" - ")
> end
>
> but I'd like to replace " -" by a new line character to display the
> full adress on 3 lines
>
> is it possible ?
>
> joss
>


def to_s
[@street, @city, @country ].compact.join("\n")
end

Josselin

9/15/2006 4:00:00 AM

0

On 2006-09-14 19:13:42 +0200, "Farrel Lifson" <farrel.lifson@gmail.com> said:

> On 14/09/06, Josselin <josselin@wanadoo.fr> wrote:
>> I would like to compact join address elements by inserting a new line
>> between them
>>
>> in my class address I am using
>>
>> def to_s
>> [@street, @city, @country ].compact.join(" - ")
>> end
>>
>> but I'd like to replace " -" by a new line character to display the
>> full adress on 3 lines
>>
>> is it possible ?
>>
>> joss
>>
>
>
> def to_s
> [@street, @city, @country ].compact.join("\n")
> end

thanks .. that's what I did, but I realize that displaying it inside a
Rails view, I should join with a "<br />"
;-))