class Factory
A Factory
is a wrapper around a Proc
that exposes it through its {Factory#new new} method.
Wrapping a Proc
in a Factory
is useful to have a uniform API across classes and custom object-creating lambdas. For instance, if a method create_object takes a class as argument, like:
def create_object(klass) obj = klass.new('foo') # do something with obj obj end
you can pass modified class constructors:
create_object(Factory.new {|arg| Array.new(4) { arg } })
and have the method behave as if the passed argument were a normal class.
Attributes
Public Class Methods
Public Instance Methods
__bind__(object)
click to toggle source
new(*args)
click to toggle source
Call the wrapped Proc
# File lib/rui/factory.rb, line 69 def new(*args) @blk[*args] end