From: Brian Candler Date: 2012-08-16T02:46:40+09:00 Subject: Re: Print method Eric Christopherson wrote in post #1072456: > Languages like Java > and Smalltalk define their text output methods on instances of IO > streams; you can actually do that in Ruby too, using something like > `$stdout.print foo`. The OO conundrum again - function acting on two objects, which object class does the function belong in? It could be either. If it were string.print and you wanted to send to a different stream, you would need to do something like "hello".print($stdout) which would work fine - Reia works this way However I can think of one good reason for doing it the Ruby way round. print/puts expects a string, and it will call to_s automatically on the argument if it is not. "foo.print" would fail on any object which doesn't have a print method - or there would have to be a print method in the top-level Object which does to_s.print. The latter would mix a public 'print' method into every object - and also risks infinite recursion if to_s doesn't actually return a string. Having a public to_s method is more generally useful than a public print method, I think. Regards, Brian. -- Posted via http://www.ruby-forum.com/.