Module: Transproc::Registry
- Defined in:
- lib/transproc/registry.rb
Overview
Container to define transproc functions in, and access them via ‘[]` method from the outside of the module
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
- .extended(target) ⇒ Object private
Instance Method Summary collapse
-
#[](fn, *args) ⇒ Transproc::Function
(also: #t)
Builds the transproc function either from a Proc, or from the module method.
-
#uses(name, options = {}) ⇒ undefined
Forwards the named method (transproc) to another module.
Class Method Details
.extended(target) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
95 96 97 |
# File 'lib/transproc/registry.rb', line 95 def self.extended(target) target.extend(ClassMethods) end |
Instance Method Details
#[](fn, *args) ⇒ Transproc::Function Also known as: t
Builds the transproc function either from a Proc, or from the module method
46 47 48 49 |
# File 'lib/transproc/registry.rb', line 46 def [](fn, *args) fun = fn.is_a?(Proc) ? fn : method(fn).to_proc Transproc::Function.new(fun, args: args) end |
#uses(name, options = {}) ⇒ undefined
Forwards the named method (transproc) to another module
Allows using transprocs from other modules without including those modules as a whole
end
module Bar
extend Transproc::Registry
uses :foo, from: Foo, as: :baz
uses :bar, from: Foo
end
Bar[:baz]['Qux'] # => 'QUX'
Bar[:bar]['Qux'] # => 'qux'
88 89 90 91 92 |
# File 'lib/transproc/registry.rb', line 88 def uses(name, = {}) source = .fetch(:from) new_name = .fetch(:as, name) define_method(new_name) { |*args| source.__send__(name, *args) } end |