10 年間の C++ から Ruby への移行を模索する中で、最も単純なことを達成する方法を次から次へと推測しています。以下の古典的な形状の派生例を考えると、これが「Ruby Way」であるかどうか疑問に思います。以下のコードに本質的な問題はないと信じていますが、Ruby の能力をフルに活用していないと感じています。
class Shape
def initialize
end
end
class TwoD < Shape
def initialize
super()
end
def area
return 0.0
end
end
class Square < TwoD
def initialize( side )
super()
@side = side
end
def area
return @side * @side
end
end
def shapeArea( twod )
puts twod.area
end
square = Square.new( 2 )
shapeArea( square ) # => 4
これは「The Ruby Way」で実装されていますか? そうでない場合、これをどのように実装しますか?