In some interactors, several functions are defined to be used in call function (I'm not using utility for organize such functions).
Is it fine to use @context
instead of context
in this situation?
Ref URL: https://github.com/collectiveidea/interactor
Thanks for any help
Asked
Active
Viewed 567 times
0

denys281
- 2,004
- 2
- 19
- 38

crazyoptimist
- 125
- 1
- 14
-
Could you give some examples? Do you meant to create affectional methods in class? Not to have only ```call``` method? – denys281 Aug 20 '20 at 06:55
-
In [max](https://stackoverflow.com/users/544825/max)'s answer, it seems fine to have additional methods inside the interactor. – crazyoptimist Aug 20 '20 at 15:46
-
It is better to have only private. – denys281 Aug 20 '20 at 15:55
-
Can you explain a bit more? I'd love to hear you. Thank you `denys281` – crazyoptimist Aug 20 '20 at 19:10
1 Answers
1
As you can see from the source code context
is just a simple accessor (getter method) declared by 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
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 MyInteractor
include Interactor
def my_method
@context
# is the exact same as
context
# except for the method call
end
end

max
- 96,212
- 14
- 104
- 165