最近尝试阅读 Rails 源代码,遇到了一个小疑问,如下:
# railties/lib/rails/initializable.rb
class Initializer
  attr_reader :name, :block
  def initialize(name, context, options, &block)
    options[:group] ||= :default
    @name, @context, @options, @block = name, context, options, block
  end
  def before
    @options[:before]
  end
  def after
    @options[:after]
  end
  def belongs_to?(group)
    @options[:group] == group || @options[:group] == :all
  end
  def run(*args)
    @context.instance_exec(*args, &block)
  end
  def bind(context)
    return self if @context
    # 疑问: 这里为什么不直接设置 `@context = context`,而是要创建新对象呢?
    Initializer.new(@name, context, @options, &block)
  end
end
有没有同学指点一下呢?