📜  ruby 扩展 - Ruby 代码示例

📅  最后修改于: 2022-03-11 15:04:45.585000             🧑  作者: Mango

代码示例1
module ReusableModule
  def module_method
    puts "Module Method: Hi there!"
  end
end

class ClassThatIncludes
  include ReusableModule
end
class ClassThatExtends
  extend ReusableModule
end

puts "Include"
ClassThatIncludes.new.module_method       # "Module Method: Hi there!"
puts "Extend"
ClassThatExtends.module_method            # "Module Method: Hi there!"