Method: Module#chain

Defined in:
lib/y_support/core_ext/module/misc.rb

#chain(**hash, &block) ⇒ Object

Defines a set of methods by applying the block on the return value of another set of methods. Accepts a hash of pairs { mapped_method_symbol => original_method_symbol } and a block which to chain to the original method result.



63
64
65
66
67
68
69
# File 'lib/y_support/core_ext/module/misc.rb', line 63

def chain **hash, &block
  hash.each_pair { |mapped_method_symbol, original_method_symbol|
    define_method mapped_method_symbol do |*args, &b|
      block.( send original_method_symbol, *args, &b )
    end
  }
end