lib/surrogate/endower.rb in surrogate-0.6.0 vs lib/surrogate/endower.rb in surrogate-0.6.1
- old
+ new
@@ -30,22 +30,30 @@
private
def endow_klass
klass.extend ClassMethods
- add_hatchery_to klass
- enable_defining_methods klass
+ add_hatchery_to klass
+ enable_defining_methods klass
klass.send :include, InstanceMethods
- invoke_hooks klass
+ enable_generic_override klass
+ invoke_hooks klass
end
def endow_singleton_class
hatchery = add_hatchery_to singleton
enable_defining_methods singleton
singleton.module_eval &block if block
klass.instance_variable_set :@hatchling, Hatchling.new(klass, hatchery)
- invoke_hooks singleton
+ invoke_hooks singleton
klass
+ end
+
+ def enable_generic_override(klass)
+ klass.__send__ :define_method, :will_override do |method_name, *args, &block|
+ @hatchling.prepare_method method_name, args, &block
+ self
+ end
end
def invoke_hooks(klass)
self.class.hooks.each { |hook| hook.call klass }
end