将一个类分解为多个文件的首选方法是什么?Mixins 可以工作,但就我而言,我只是想更好地组织一个非常大的班级。在下面介绍的两种方法中,其中一种是否比另一种“更好”?
文件_A.rb
require 'file_B_class'
require 'file_B_mixin'
class ReallyBigClass
include ReallyBigClassFileB
def primary_method
puts "I'm the primary method"
end
end
文件_B_class.rb
class ReallyBigClass
def support_method_as_class
puts "I'm included in the main class by appending code"
end
end
文件_B_mixin.rb
module ReallyBigClassFileB
def support_method_as_mixin
puts "I'm included in the main class by mixin"
end
end