何かを成し遂げるために、モジュールとクラスをいじっています。
私が使用した継承を一切行わずに MyClass を起動するとclass MyClass::A4.generate
、A4 が format 関数をオーバーライドします。
A4はこんな感じです。
class A4 < MyClass
def somefunction
format = { :width => 200, :height => 100 }
end
end
しかし今、私は複数のクラスを (さまざまな種類のファイルを生成して) いくつかの形式に作成したいと考えています。
私の最初の試みはclass MyClass < AnotherClass
.
2 番目の試行は、もう少し Ruby に似ています。
module AnotherModule
def somefunction
format = { :width => 50 }
end
end
class MyClass
include AnotherModule
def initialize
end
......
end
このようなことは可能ですか?
class A4 < AnotherModule
def somefunction
format = { :width => 200, :height => 100 }
end
end
MyClass::A4.new.generate
もしそうなら、どのように?