Module: Reight::Hookable
- Included in:
- App::Chips, Button, Index, SoundEditor::Canvas, SpriteEditor::Canvas, Text
- Defined in:
- lib/reight/helpers.rb
Instance Method Summary collapse
Instance Method Details
#hook(*names) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/reight/helpers.rb', line 30 def hook(*names) names.each do |name| singleton_class.__send__ :define_method, name do |&block| @hookable_hooks ||= {} (@hookable_hooks[name] ||= []).push block end singleton_class.__send__ :define_method, "#{name}!" do |*args, &block| @hookable_hooks&.[](name)&.each {_1.call(*args, &block)} end end end |