DEV Community

Cover image for Pimp My Code : Come and Clean Code with V #1

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

Pimp My Ruby on November 29, 2023

I started coding in Ruby four years ago. In these four years, I've built many applications and made a lot of mistakes. What if today we take a lit...
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