Module: Stateology::SM_Class_Methods
- Defined in:
- lib/stateology.rb
Overview
class methods
Instance Method Summary collapse
Instance Method Details
#state(name, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/stateology.rb', line 28 def state(name, &block) if RUBY_VERSION =~ /1.9/ pram = [false] else pram = [] end # if const is defined here then module_eval if const_defined?(name, *pram) then m = self.const_get(name) m.module_eval(&block) else m = Module.new # if the state is defined further up the chain then "inherit it" if constants.include?(name) || constants.include?(name.to_s) then # if constant not defined here then must be inherited inherited_state = const_get(name) # ignore if the constant is not a module m.send(:include, inherited_state) if inherited_state.instance_of?(Module) end m.send(:include, Stateology) m.module_eval(&block) const_set(name, m) end end |