Module: NoBacksies
- Defined in:
- lib/no_backsies.rb
Overview
NoBacksies module ecapsulates all supported callback mixins.
NoBackseis::Callbacks can be mixed-in and all supported callbacks will be applied to the class or module.
class Y
include NoBacksies::Callbacks
def self.list
@list ||= []
end
callback :method_added do |method|
list << method
end
def foo; end
def ; end
end
Y.list.assert #=> [:foo, :bar]
Using callbacks can easily lead to infinite loops. NoBacksies makes it easier to control callback expression via the #callback_express method.
class Z
include NoBacksies::Callbacks
def self.list
@list ||= []
end
callback :method_added do |method|
callback_express :method_added=>false do
define_method("#{method}!") do
send(method) + "!"
end
end
end
def foo; "foo"; end
def ; "bar"; end
end
y = Y.new
y.foo! #=> "foo!"
NOTE: Currently the NoBackies module only supports class level callbacks. We will look into adding instance level callbacks in a future version.
– TODO: What about adding ‘super if defined?(super)` to callback methods? Should this be standard? Should it occur before or after? Or should in be controlled via a special callback, e.g. `callback method_added, :super`? ++
Defined Under Namespace
Modules: CallbackMethods, Callbacks, ConstMissing, Extended, Included, Inherited, MethodAdded, MethodRemoved, MethodUndefined, SingletonMethodAdded, SingletonMethodRemoved, SingletonMethodUndefined