These are chat archives for dry-rb/chat

18th
Jun 2017
Andrew Kozin
@nepalez
Jun 18 2017 11:46

I see. Still I'm sure it is out the scope of the gem.

A more general implementation for with would be the following:

def with(**options)
  dup.tap |obj|
    options.each do |key, val|
      obj.instance_variable_set "@#{key}", val
    end
  end
end

You can see that it deals nothing with a way an object has been initialized. That way could be... well... strange:

param  :weird, optional: true
option "some weird key", as: :weird, optional: true

But in with we shouldn't deal with such a complexity, it could work both with and without dry-initializer. There is no need to bind it to the gem.

From the other hand, I can imagine (OMG, i have) classes using the gem, where with has already allocated for other puposes -- I would not be glad if they stop working because of unnecessary addition to the gem.

@flash-gordon ^^
Nikita Shilnikov
@flash-gordon
Jun 18 2017 19:35
@nepalez oh, it was meant to be an opt-in method ofc, I'd love to see something like extend Dry::Initializer[undefined: false, with: true], wdyt? The reason I need this in dry-initializer is quite simple, to have a general solution I need to know the list of sequential arguments (params) and it's either can be available in dry-initializer itself (via a plugin or a hook) or via a public API (that is not here atm)