Module: Surrogate::ClassMethods

Defined in:
lib/surrogate/endower.rb

Overview

use a module so that the method is inherited (important for substitutability)

Instance Method Summary collapse

Instance Method Details

#cloneObject



90
91
92
93
94
95
96
97
98
# File 'lib/surrogate/endower.rb', line 90

def clone
  hatchling, hatchery = @hatchling, @hatchery
  Class.new self do
    Surrogate.endow self do
      hatchling.api_methods.each { |name, options| define name, options.to_hash, &options.default_proc }
    end
    hatchery.api_methods.each { |name, options| define name, options.to_hash, &options.default_proc }
  end
end

#new(*args) ⇒ Object

Custom new, because user can define initialize, and ivars should be set before it



101
102
103
104
105
106
# File 'lib/surrogate/endower.rb', line 101

def new(*args)
  instance = allocate
  instance.instance_variable_set :@hatchling, Hatchling.new(instance, @hatchery)
  instance.send :initialize, *args
  instance
end