Module: Instantiable

Defined in:
lib/standard/facets/instantiable.rb

Overview

Instantiable

Initialize modules, almost as if they were classes.

Alows a module to be used much like a class, by defining a #new method that creates a class on demand.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.append_features(mod) ⇒ Object



10
11
12
# File 'lib/standard/facets/instantiable.rb', line 10

def self.append_features(mod)
  mod.extend self
end

Instance Method Details

#new(*args, &blk) ⇒ Object

Never use a class again! ;)



16
17
18
19
20
# File 'lib/standard/facets/instantiable.rb', line 16

def new(*args,&blk)
  mod = self
  @instantiable_class ||= Class.new{include mod}
  @instantiable_class.new(*args,&blk)
end