デザインパターンfactry_method

factory_methodパターンです
http://www.techscore.com/tech/DesignPattern/FactoryMethod.html
主ロジックで使用する
インスタンスをサブクラスで切り替えられるパターン
これもよく見るパターンですね


class Wood
attr_accessor(:str)
def initialize
@str = ""
end
end
class Potato < Wood
attr_accessor(:str)
def initialize
super
@str += "´з`)y--゜゜::"
end
end
class AbstractCutPrint
def draw(hanzai); end
def cut(hanzai); end
def print(hanzai); end
def cerate_cuttable
return Wood.new
end
def create_cut_print
hanzai = create_cuttable
draw(hanzai)
cut(hanzai)
print(hanzai)
end
end

class ImagawasCutPrint < AbstractCutPrint
def draw(hanzai)
hanzai.str += "絵を描く。"
end
def cut(hanzai)
hanzai.str += "もんもんを彫る。"
end
def print(hanzai)
puts hanzai.str
end
def create_cuttable
return Potato.new
end
end

#----------------------
i = ImagawasCutPrint.new
i.create_cut_print