Module: Doodle::Factory

Extended by:
ClassMethods
Defined in:
lib/doodle/factory.rb

Overview

A factory function is a function that has the same name as a class which acts just like class.new. For example:

Cat(:name => 'Ren')

is the same as:

Cat.new(:name => 'Ren')

As the notion of a factory function is somewhat contentious [xref ruby-talk], you need to explicitly ask for them by including Factory in your base class:

class Animal < Doodle
  include Factory
end
class Dog < Animal
end
stimpy = Dog(:name => 'Stimpy')

etc.

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

RX_IDENTIFIER =
/^[A-Za-z_][A-Za-z_0-9]+\??$/

Method Summary

Methods included from ClassMethods

factory, included