[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: defining a 'puts' or a 'print' for a class

Gavri Savio Fernandez

11/26/2003 6:59:00 PM

> -----Original Message-----
> From: Zach Dennis [mailto:zdennis@mktec.com]
> Subject: defining a 'puts' or a 'print' for a class

>
> e = Email.new( ...stuff here... )
> puts Email.print
>
>
>
> But I would love to say:
>
> puts Email
>
> to get the same result.
>

if you actually meant
puts e
all you need to do is define the 'to_s' method to return the String you need to print

class Email
def to_s
"arbitary string"
end
end

puts e


> Any ideas?
>
> Thanks,
>
> Zach
>
>


Gavri Savio Fernandez
___________________________________________
I can't stand cheap people. It makes me real mad when someone says something like, "Hey, when are you going to pay me that $100 you owe me?" or "Do you have that $50 you borrowed?" Man, quit being so cheap! - Jack handy