我可以在交互器 class 中将上下文用作 @context 吗?
Can I use the context as @context inside an interactor class?
在一些交互器中,定义了几个函数用于调用函数(我没有使用实用程序来组织这些函数)。
在这种情况下可以使用 @context
而不是 context
吗?
参考 URL: https://github.com/collectiveidea/interactor
感谢您的帮助
从源代码可以看出,context
只是一个简单的访问器(getter方法),由attr_reader
声明:
module Interactor
# Internal: Install Interactor's behavior in the given class.
def self.included(base)
base.class_eval do
extend ClassMethods
include Hooks
# Public: Gets the Interactor::Context of the Interactor instance.
attr_reader :context
end
end
因此,直接访问实例变量 (@context
) 和通过 context
方法访问之间几乎没有明显区别,只要您从 class 中访问它包括这个模块。
class MyInteractor
include Interactor
def my_method
@context
# is the exact same as
context
# except for the method call
end
end
在一些交互器中,定义了几个函数用于调用函数(我没有使用实用程序来组织这些函数)。
在这种情况下可以使用 @context
而不是 context
吗?
参考 URL: https://github.com/collectiveidea/interactor
感谢您的帮助
从源代码可以看出,context
只是一个简单的访问器(getter方法),由attr_reader
声明:
module Interactor
# Internal: Install Interactor's behavior in the given class.
def self.included(base)
base.class_eval do
extend ClassMethods
include Hooks
# Public: Gets the Interactor::Context of the Interactor instance.
attr_reader :context
end
end
因此,直接访问实例变量 (@context
) 和通过 context
方法访问之间几乎没有明显区别,只要您从 class 中访问它包括这个模块。
class MyInteractor
include Interactor
def my_method
@context
# is the exact same as
context
# except for the method call
end
end