Last active
June 13, 2018 18:34
-
-
Save jilucev/05db1fb5bb0dc58011c139207a6948d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Foo | |
class Bar | |
attr_accessor :qux_service, | |
:param1, | |
:param2 | |
#initialize the class and dependencies | |
def initialize(foo_klass = Foo) | |
@foo_klass = foo_klass | |
#initialize dependencies | |
@qux_service = Foo::QuxService.new | |
end | |
def call(bar_id, param1, param2) | |
@param1 = param1 | |
@param2 = param2 | |
call_qux_service | |
end | |
private | |
def call_qux_service | |
qux_service.(param1, param2) | |
end | |
end | |
end | |
module Foo | |
class QuxService | |
attr_accessor :qux_klass | |
def initialize(qux_klass = Qux) | |
@qux_klass = qux_klass | |
end | |
def call(param1, param2) | |
param1 + param2 | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Foo | |
class Bar | |
attr_accessor :param1, | |
:param2 | |
#initialize the class and dependencies | |
def initialize(foo_klass = Foo) | |
@foo_klass = foo_klass | |
end | |
def call(bar_id, param1, param2) | |
@param1 = param1 | |
@param2 = param2 | |
call_qux_service | |
end | |
private | |
def call_qux_service | |
::QuxService.do_a_thing(param1, param2) | |
end | |
end | |
end | |
module QuxService | |
extend self | |
def do_a_thing(param1, param2) | |
param1 + param2 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment