2011-07-19 1 views

答えて

1

はあなたが意味するか:

module Foo 
    def bar 
    @bar ||= 0 
    @bar += 1 
    end 
end 

class Tester 
    include Foo 
    def baz 
    @bar ||= 0 
    @bar += 500 
    end 
end 

t = Tester.new 
t.bar #=> 1 
t.baz #=> 501 
t.bar #=> 502 
t.bar #=> 503 
t.baz #=> 1003 

その場合は、[はい。やや関連したメモでは、difference between include and extendの説明が役に立つかもしれません。

関連する問題