DEV Community

Discussion on: Pimp My Code : Come and Clean Code with V #1

Collapse
 
tedma4 profile image
Ted Martinez

You keep using .call like a class method, but it's defined as an instance method, is there a reason for that?

Collapse
 
pimp_my_ruby profile image
Pimp My Ruby

Yes, it's a little oversight on my part. Actually all my Services inerhit from a base class called ApplicationService

require 'dry/monads'

class ApplicationService
  include Dry::Monads[:result, :do, :maybe, :try]

  def self.call(...)
    new(...).call
  end
end
Enter fullscreen mode Exit fullscreen mode

I only use initializer for inject the dependencies (other classes that needs to be called inside my class). But all the parameters related to the behavior of my class are submitted in the .call method