barsoom / attr_extras

Takes some boilerplate out of Ruby with methods like attr_initialize.
MIT License
560 stars 31 forks source link

Do not dup class and module name constants #48

Open matas-zanevicius opened 1 year ago

matas-zanevicius commented 1 year ago

Say I want a service that calls another service. I can inject the class as a named argument.

class MyServiceA
  method_object [:other_service]

  def call
    other_service.call
  end
end

But if I wanted to define a default service, I would end up with an anonymous class.

class MyServiceB
  def self.call
    # do stuff
  end
end

class MyServiceA
  method_object [other_service: MyServiceB]

  def call
    other_service.call
  end
end

In many cases, it is not a big problem, but it does not make much sense to duplicate a class or a module either.

This PR is a possible solution.