From: Henry Maddocks Date: 2012-08-16T08:48:56+09:00 Subject: Re: Print method On 16/08/2012, at 4:17 AM, Fred McArthur wrote: > But when I do x.print or "abc".print it throws an error. I have to use > print x or print "abc", which seems to violate the "least surprise" > principle and causes sleep deprivation in clueless newbies like me. > Also, > things like print x.upcase.reverse just drive me up a wall. Why not > x.upcase.reverse.print? I know it's a common example in OOD text books, that an object has a print method (or draw or display), but that design is wrong. "abc".print makes the assumption that String has knowledge of where and how it will be 'printed'. String's print implementation will have be able to print to all known output devices. If another output device is invented String will have to be updated or it won't be able to print to it. Sure you could do "abc".print( device) but that will put unnecessary restrictions on the devices interface. The correct way to do this is have each device know which types it can print and how to print them. $stdout.puts "abc" The MVC pattern works this way. Ruby has done the correct thing. Henry