Overloading << operator

How do I create a class that will allow me to pass a string, for
example, to an instance of it using the << operator? Like this:

···

#==================================
class Logger
include Singleton

end
$logger = Logger.instance

$logger << “Here is a log message”
#==================================

Thanks,
Carl

Hi –

How do I create a class that will allow me to pass a string, for
example, to an instance of it using the << operator? Like this:

#==================================
class Logger
include Singleton

end
$logger = Logger.instance

$logger << “Here is a log message”
#==================================

<< is just a method, so you can redefine it:

class Logger
def <<(s)
# do something with s
end
end

David

···

On Fri, 19 Dec 2003, Carl Youngblood wrote:


David A. Black
dblack@wobblini.net