2011-07-19 42 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