[英]Can I use the context as @context inside an interactor class?
In some interactors, several functions are defined to be used in call function (I'm not using utility for organize such functions).在某些交互器中,定义了几个函数以在调用 function 中使用(我没有使用实用程序来组织此类函数)。
Is it fine to use @context
instead of context
in this situation?在这种情况下使用
@context
而不是context
可以吗?
Ref URL: https://github.com/collectiveidea/interactor参考 URL: https://github.com/collectiveidea/interactor
Thanks for any help谢谢你的帮助
As you can see from the source code context
is just a simple accessor (getter method) declared by attr_reader
:从源代码
context
中可以看出,它只是attr_reader
声明的一个简单的访问器(getter 方法):
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
There is thus almost no discernible difference between accessing the instance variable directly ( @context
) and through the context
method as long as you're accessing it from within the class that includes this module.因此,只要您从包含此模块的 class 中访问实例变量,直接访问实例变量 (
@context
) 和通过context
方法几乎没有明显区别。
class MyInteractor
include Interactor
def my_method
@context
# is the exact same as
context
# except for the method call
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.