re: API and Provider methodology VIEW POST

thing[PROVIDER_NAME].send(method, result ? *result : *args)

The above is very dangerous approach, since if one of the methods in the pipe return nil on purpose, the next method will be fed with initial arguments, silently introducing the very hard-to-catch bug.

Also, pipelines in modern ruby are easier to accomplish with Module#prepend, just enforcing the formatter to be declared as a module responding to call and doing something like:

def pipeline_for(method, *pipeline)
  pipeline.each do |mod|
    prepend {
      define_method method, *args, **kwargs, &λ do
        super(mod.(*args, **kwargs, &λ))

You're not wrong, I would normally add insurance to insure that the output or the next output is returned but as I said at the bottom of my post, I never actually tested the code and was never intended to be properly used, merely ideas and examples to get the ball rolling, which is why I made it simple!

code of conduct - report abuse