Skip to content

Instantly share code, notes, and snippets.

@matheusazzi
Last active May 18, 2023 11:36
Show Gist options
  • Select an option

  • Save matheusazzi/ae04d27e1bdf3b57a30469d9f460c437 to your computer and use it in GitHub Desktop.

Select an option

Save matheusazzi/ae04d27e1bdf3b57a30469d9f460c437 to your computer and use it in GitHub Desktop.
class ThingService
attr_reader :param1, :param2
Result = Struct.new(:success?, :things, :error)
def self.call(param1, param2)
new(param1, param2).call
end
def call
do_something
end
private
def initialize(param1, param2)
@param1 = param1
@param2 = param2
end
def do_something
@something ||= find_things
if @something.success?
Result.new(true, [...], nil)
else
Result.new(false, [], '...')
end
end
def find_things
# ...
end
end
ThingService.call(param1, param2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment