Module: DuckPuncher::Registration
- Included in:
- DuckPuncher
- Defined in:
- lib/duck_puncher/registration.rb
Overview
Note:
When updating this file please update comment regarding this module in duck_puncher.rb
Instance Method Summary collapse
-
#deregister(*targets) ⇒ Object
Remove extensions for a given class or list of classes.
-
#register(target, *mods, &block) ⇒ Object
Register an extension with a target class When given a block, the block is used to create an anonymous module.
-
#register!(*args, &block) ⇒ Object
Register an extension and then immediately activate it See #register for accepted arguments.
Instance Method Details
#deregister(*targets) ⇒ Object
Remove extensions for a given class or list of classes
32 33 34 35 |
# File 'lib/duck_puncher/registration.rb', line 32 def deregister(*targets) targets.each &Ducks.list.method(:delete) targets.each &decorators.method(:delete) end |
#register(target, *mods, &block) ⇒ Object
Register an extension with a target class When given a block, the block is used to create an anonymous module
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/duck_puncher/registration.rb', line 12 def register(target, *mods, &block) = mods.last.is_a?(Hash) ? mods.pop : {} mods << Module.new(&block) if block target = DuckPuncher.lookup_constant target Ducks.list[target] = Set.new [] unless Ducks.list.key?(target) mods = Array(mods).each do |mod| duck = UniqueDuck.new Duck.new(target, mod, ) Ducks.list[target] << duck end [target, *mods] end |
#register!(*args, &block) ⇒ Object
Register an extension and then immediately activate it See #register for accepted arguments
26 27 28 29 |
# File 'lib/duck_puncher/registration.rb', line 26 def register!(*args, &block) register *args, &block call args.first end |