On 8/28/08, Brian A. <judobrian+ruby-forum / gmail.com> wrote:
> Shashank Agarwal & Matthias Reitinger wrote:
> >
> > puts sandy
> >
>
> Thank you both that did work, but opened a new issue for me.
>
> When I change the def to_s within the Person class to this (adding the
> @address):
>
> ========================================================================
> def to_s
>    @first_name + " " + @last_name + "\n" + \
>    @email + "\n"
>    @address
> end
> ========================================================================
>
> I get this "#<Person:0x2b3340c>", is this because the Person class makes
> reference to the Address class, and its the address class has its own
> to_s that prints?   Should I move the @street + "\n" + \, ...etc to the
> Person class from the Address class?
>
You are right, the Address class does have its own #to_s.  The issue
here is that when you type @address, you are not automatically calling
it.  You need to do @address.to_s.    (The puts method does
automatically call #to_s on its arguments, but it is not recursive).

Also, you probably want a '+' after the @email + "\n".  Methods return
the value of the last line, so without you will only return the
address, not the name and email from the previous lines.

-Adam