extend

在类定义中引入module后,module中的方法成为类的类方法。 
在类定义中用extend引入module。 
例如: 
module Base 
  def test 
    p "This is a class method!" 
  end 
end 

class Car 
  extend Base 
end

Car.test => "This is a class method!" 


发布了20 篇原创文章 · 获赞 3 · 访问量 1万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章