Module: Petra::Util::Registrable::ClassMethods
- Defined in:
- lib/petra/util/registrable.rb
Instance Method Summary collapse
-
#acts_as_register(name) ⇒ Object
Generates helper methods from the given name.
Instance Method Details
#acts_as_register(name) ⇒ Object
Generates helper methods from the given name.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/petra/util/registrable.rb', line 25 def acts_as_register(name) name = name.to_s define_singleton_method("registered_#{name.pluralize}") do @registered_components ||= {} @registered_components[name.to_s] ||= {} end define_singleton_method("registered_#{name}") do |key| send("registered_#{name.pluralize}")[key.to_s] end define_singleton_method("register_#{name}") do |key, value| send("registered_#{name.pluralize}")[key.to_s] = value end define_singleton_method("registered_#{name}?") do |key| send("registered_#{name.pluralize}").key?(key.to_s) end end |