Let's write β

プログラミング中にできたことか、思ったこととか

RubyだとMixinで

RubyだとMix-inで可能ですね

# Test Mixin
module DoubleSayMixin
        def doubleSay()
                say()
                say()
        end
end

#Phrase One
puts "---- Test 1 -----"
class ParentClassOne
        def say()
                puts "ParentOne Say()"
        end
end

class SampleClassOne < ParentClassOne
        include DoubleSayMixin
end

class SampleClassTwo < ParentClassOne
        include DoubleSayMixin
        def say()
                puts "SampleClassTwo Say()"
        end
end
o = SampleClassOne.new()
o.doubleSay()
o = SampleClassTwo.new()
o.doubleSay()

#Phrase 2
puts "------- test 2 -----"
class ParentClassTwo
        def say()
                puts "ParentTwo Say()"
        end
end
class ParentClassThree
        def say()
                puts "ParentThree Say()"
        end
end

class SampleClassThree < ParentClassTwo
        include DoubleSayMixin
        def say()
                puts "SampleThree Say()"
        end
end

class SampleClassFour < ParentClassOne
        include DoubleSayMixin
        def say()
                puts "SampleFour Say()"
        end
end

o = SampleClassThree.new()
o.doubleSay()
o = SampleClassFour.new()
o.doubleSay()
---- Test 1 -----
ParentOne Say()
ParentOne Say()
SampleClassTwo Say()
SampleClassTwo Say()
------- test 2 -----
SampleThree Say()
SampleThree Say()
SampleFour Say()
SampleFour Say()

僕が働いているAzit.incでは一緒に働けるエンジニアを募集しています!
採用情報 — 株式会社アジット|Azit Inc.