Skip to content

Instantly share code, notes, and snippets.

@jilucev
Last active June 13, 2018 18:34
Show Gist options
  • Save jilucev/05db1fb5bb0dc58011c139207a6948d5 to your computer and use it in GitHub Desktop.
Save jilucev/05db1fb5bb0dc58011c139207a6948d5 to your computer and use it in GitHub Desktop.
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
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