Module: Composite::ClassMethods
- Defined in:
- lib/composite.rb
Overview
Internal module to extend class that includes this module. This trick of getting around the fact that module methods aren’t inherited when a module is included is from: wiki.rubyonrails.org/rails/pages/SimpleAccessControlExample
Instance Method Summary collapse
-
#part(*parts, &block) ⇒ Object
Metaprogramming keyword to define ‘part’ instance variables that automatically call compose/decompose on access.
Instance Method Details
#part(*parts, &block) ⇒ Object
Metaprogramming keyword to define ‘part’ instance variables that automatically call compose/decompose on access.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/composite.rb', line 23 def part (*parts, &block) parts.each do |aPart| set_method = (aPart.to_s+'=').to_sym get_method = aPart.to_sym instance = ('@'+aPart.to_s).to_sym send :define_method, get_method do || decompose instance_variable_get instance end send :define_method, set_method do |a| decompose #call.block instance_variable_set instance, a compose end end end |