From: "Jan E." Date: 2012-08-17T18:07:36+09:00 Subject: Re: Print method Fred McArthur wrote in post #1072622: > But why it's not done that way in the first place still escapes me. For > instance, I understand the statement: > > ### "foo.print" would fail on any object which doesn't have a print > method > > But so would reverse, upcase, downcase and all the other methods that > ARE done with dotted notation. Also if print is a private method, then > why aren't the others? I gather it has a lot to do with selection of > output devices, but isn't the idea of OO based in part on polymorphism, > therefore able to handle that (I'm taking a wild shot here)? With polymorphism you probably mean that the method acts differently depending on the output device. The problem with this is that you certainly don't want to hardcode the output logic for some devices into your method. This wouldn't make any sense (as Henry already said). So the method would have to delegate the call to the output object. In other words, you need two different methods: IO#print(String) --> the actual output logic String#show(IO) --> for printing a string-like object on a device This actually makes a lot of sense. And as you've already seen, that's pretty much what Ruby does with "print" and "display". The only criticism I can think of is that the top level "print" should be removed. This would force you to either write $stdout.print("Hallo") or "Hallo".display instead of using this pseudo-imperative style. -- Posted via http://www.ruby-forum.com/.