# Puts return

**URL:** <https://www.ruby-forum.com/t/puts-return/180627>\
**Category:** Ruby\
**Created:** [December 24, 2009, 12:24am UTC](https://www.ruby-forum.com/t/puts-return/180627 "2009-12-24T00:24:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![edresende](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7cd45c/32.png) [@edresende](https://www.ruby-forum.com/u/edresende)\
**Post date:** [December 24, 2009, 12:24am UTC](https://www.ruby-forum.com/t/puts-return/180627/1 "2009-12-24T00:24:39Z")

</div>

Hello guys, i’m new in ruby and i’m trying to create an Address Book.  
(I’m from Brasil)  
When i put the book to print  
“puts lista” #lista is the Address Book  
the method to\_s of the AddresBook class is like this:  
"def to\_s  
puts “Lista Telefonica”  
puts "Numero de Contatos: " + @qtContatos.to\_s  
@persons.each do |pessoa|  
#persons is an array of a Class Person that have it’s own to\_s method  
puts pessoa  
puts “”  
end  
end  
"

It’s working well, but when I run it in the cmd:  
“C:\Users\Dudu.gem\exe\>ruby ListaTelefonica.rb”  
(I’m using Windows 7 with Gems version “1.3.5”)

The print Returns the & (address) of each thing I print…  
example:  
"  
Nome: My Name  
Email: removed\_email\_address@domain.invalid  
Fone: XXXXXXX  
Endereco:  
Rua NumSei, 321  
Cidade: Anyone  
Pais: Brasil  
#Address:0x2803ae0  
#Pessoa:0x2803b20

#AddressBook:0x28043a0  
"

How can I take this Address out??  
this “#AddressBook:0x28043a0” and the others  
:S  
Thanks!!!

---

<div class="post-metadata">

**Author:** ![edresende](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7cd45c/32.png) [@edresende](https://www.ruby-forum.com/u/edresende)\
**Post date:** [December 24, 2009, 12:41am UTC](https://www.ruby-forum.com/t/puts-return/180627/2 "2009-12-24T00:41:33Z")

</div>

up?

---

<div class="post-metadata">

**Author:** ![edresende](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7cd45c/32.png) [@edresende](https://www.ruby-forum.com/u/edresende)\
**Post date:** [December 24, 2009, 1:52am UTC](https://www.ruby-forum.com/t/puts-return/180627/3 "2009-12-24T01:52:29Z")

</div>

Eduardo R. wrote:

> up?

Be patient.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![edresende](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7cd45c/32.png) [@edresende](https://www.ruby-forum.com/u/edresende)\
**Post date:** [December 25, 2009, 5:33pm UTC](https://www.ruby-forum.com/t/puts-return/180627/4 "2009-12-25T17:33:44Z")

</div>

On Dec 23, 2009, at 3:24 PM, Eduardo R. wrote:

> puts pessoa  
> puts “”  
> end

First of all, method to\_s() should _return_ a string, not print it. So,  
remove puts() from to\_s() and simply return a string. In your case,  
return from to\_s() is the content of your @persons array, it gets  
printed by your “puts lista” statement.

You can do something like the following:

def to\_s  
[  
“Lista Telefonica”,  
“Numero de Contatos: #{@qtContatos}”,  
@persons.map { |pessoa|  
pessoa.to\_s  
}  
].join("\n")  
end

Then, if to\_s() for objects in your @persons array is defined  
accordingly, you should have a nice looking output.

Gennady.

---

<div class="post-metadata">

**Author:** ![edresende](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7cd45c/32.png) [@edresende](https://www.ruby-forum.com/u/edresende)\
**Post date:** [December 30, 2009, 3:15am UTC](https://www.ruby-forum.com/t/puts-return/180627/5 "2009-12-30T03:15:41Z")

</div>

Eduardo R. wrote:

> Thanks for the help =D  
> And i’ll try to understand how this works… couse i’m a beginner in  
> ruby! hehehe  
> Bye!
> 
> > def to\_s  
> > [  
> > “Lista Telefonica”,  
> > “Numero de Contatos: #{@qtContatos}”,  
> > @persons.map { |pessoa|  
> > pessoa.to\_s  
> > }  
> > ].join("\n")  
> > end

class x  
def y(@y1,@y2)  
end

def to\_s  
@y1  
@y2  
end  
end

---

<div class="post-metadata">

**Author:** ![edresende](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7cd45c/32.png) [@edresende](https://www.ruby-forum.com/u/edresende)\
**Post date:** [December 28, 2009, 7:51am UTC](https://www.ruby-forum.com/t/puts-return/180627/6 "2009-12-28T07:51:51Z")

</div>

Thanks for the help =D  
And i’ll try to understand how this works… couse i’m a beginner in  
ruby! hehehe  
Bye!

> def to\_s  
> [  
> “Lista Telefonica”,  
> “Numero de Contatos: #{@qtContatos}”,  
> @persons.map { |pessoa|  
> pessoa.to\_s  
> }  
> ].join("\n")  
> end

---

<div class="post-metadata">

**Author:** ![edresende](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7cd45c/32.png) [@edresende](https://www.ruby-forum.com/u/edresende)\
**Post date:** [December 30, 2009, 7:45pm UTC](https://www.ruby-forum.com/t/puts-return/180627/7 "2009-12-30T19:45:28Z")

</div>

Thanks to u all =D  
i’ll read a bit more about ruby to undersand everything  
Hugs!
