Zach Dennis
11/26/2003 7:14:00 PM
It would and it does. Thanks Dale for your response!
-----Original Message-----
From: Dale Martenson [mailto:dmartenson@multitech.com]
Sent: Wednesday, November 26, 2003 2:02 PM
To: ruby-talk ML
Subject: Re: defining a 'puts' or a 'print' for a class
On Wed, 2003-11-26 at 12:48, Zach Dennis wrote:
I've got a class called Email and right now i have:
class Email
def initialize
....stuff here....
end
def print
return ....stuff here....
end
end
e = Email.new( ...stuff here... )
puts Email.print
But I would love to say:
puts Email
to get the same result.
Any ideas?
You could do something like:
class Email
def initialize(email)
@email = email
end
def to_s
@email
end
end
e = Email.new("bob@mail.com")
puts e
Would that work for you?