有关最佳方法的建议,不需要使用'::'来使用模块中的类(如下所示)?
使用import/mixin?这不是一个多继承案例吗?只想简化代码.在这种情况下使用导入是否有副作用?
module Shapes
class Circle
class RightTriangle
end
class ShapeUser
def go
shape1 = Shapes::Circle.new
** prefer to use just shape1 = Circle.new
....
end
Run Code Online (Sandbox Code Playgroud)
include 模块:
class ShapeUser
include Shapes
def go
shape1 = Circle.new
# ...
end
end
Run Code Online (Sandbox Code Playgroud)
所有这一切都发生在这里的是你正在常数Circle,RightTriangle等提供给类ShapeUser.这是一个完全合理的使用include:)