# Compact join with new line

**URL:** <https://www.ruby-forum.com/t/compact-join-with-new-line/68718>\
**Category:** Ruby\
**Created:** [September 14, 2006, 7:07pm UTC](https://www.ruby-forum.com/t/compact-join-with-new-line/68718 "2006-09-14T19:07:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josselin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Josselin](https://www.ruby-forum.com/u/Josselin)\
**Post date:** [September 14, 2006, 7:07pm UTC](https://www.ruby-forum.com/t/compact-join-with-new-line/68718/1 "2006-09-14T19:07:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Josselin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Josselin](https://www.ruby-forum.com/u/Josselin)\
**Post date:** [September 14, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/compact-join-with-new-line/68718/2 "2006-09-14T19:15:06Z")

</div>

On 14/09/06, Josselin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> full adress on 3 lines
> 
> is it possible ?
> 
> joss

def to\_s  
[@street, @city, @country].compact.join(“\n”)  
end

---

<div class="post-metadata">

**Author:** ![Josselin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Josselin](https://www.ruby-forum.com/u/Josselin)\
**Post date:** [September 14, 2006, 7:15pm UTC](https://www.ruby-forum.com/t/compact-join-with-new-line/68718/3 "2006-09-14T19:15:06Z")

</div>

On 9/14/06, Josselin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> but I’d like to replace " -" by a new line character to display the  
> full adress on 3 lines
> 
> is it possible ?

Well I hope so 😉  
%w{ here you go my friend}.join(“\n”)

HTH  
robert

joss

> 

–  
Deux choses sont infinies : l’univers et la bÃªtise humaine ; en ce qui  
concerne l’univers, je n’en ai pas acquis la certitude absolue.

- Albert Einstein

---

<div class="post-metadata">

**Author:** ![Josselin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de0a6/32.png) [@Josselin](https://www.ruby-forum.com/u/Josselin)\
**Post date:** [September 15, 2006, 6:07am UTC](https://www.ruby-forum.com/t/compact-join-with-new-line/68718/4 "2006-09-15T06:07:08Z")

</div>

On 2006-09-14 19:13:42 +0200, “Farrel L.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
said:

> > but I’d like to replace " -" by a new line character to display the  
> > end  
> > thanks … that’s what I did, but I realize that displaying it inside a  
> > Rails view, I should join with a “  
> > ”  
> > ;-))
