From: william l kleb Date: 2001-03-22T20:40:02+09:00 Subject: [ruby-talk:13065] Weirich's polymorphism coding challenge While searching for some information on polymorphism, I came across another language comparison: Jim Weirich's site at http://w3.one.net/~jweirich/oostuff/ Chris Rathman has contributed a Ruby version of this simple circle/rectangle shape polymorphism example. However, Chris's code does not appear to take advantage of the succinctness that Ruby allows. For example Chris's base class, Shape.rb, class Shape attr :x attr :y # constructor def initialize(initx, inity) setX(initx) setY(inity) end # get the x & y components for the object def getX return @x end def getY return @y end # set the x & y components for the object def setX(newx) @x = newx end def setY(newy) @y = newy end # move the x & y position of the object def moveTo(newx, newy) setX(newx) setY(newy) end def rMoveTo(newx, newy) moveTo(newx + getX, newy + getY) end end It seems that this class is at least twice as long as it should be? Also, as Dave and /\ndy suggest, it should also include a "cultural" unit test. -- bil