Module: FSM::Util::ClassMethods

Includes:
Methods
Defined in:
lib/fsm-0.0.0/util.rb

Instance Method Summary collapse

Methods included from Methods

#bcall, #const, #ex, #icall, #initialize, #instance_exec, #klass, #mcall, #sh, #singleton_class, #string, #string_list, #system

Instance Method Details

#delegate(hash = {}) ⇒ Object



146
147
148
149
150
151
152
153
154
155
# File 'lib/fsm-0.0.0/util.rb', line 146

def delegate hash = {} 
  methods, to = hash.to_a.first
  methods.each do |m|
    module_eval "      def \#{ m } *a, &b\n        \#{ to }.\#{ m } *a, &b\n      end\n    code\n  end\nend\n"

#tattrs(*ms) ⇒ Object Also known as: tattr



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/fsm-0.0.0/util.rb', line 127

def tattrs *ms
  ms.flatten.each do |m|
    module_eval "      def \#{ m }(*a, &b)\n        if a.empty?\n          sh{ @\#{ m } }\n        else\n          self.\#{ m }= a.shift\n        end\n      end\n      alias_method '\#{ m }?', '\#{ m }'\n      def \#{ m }= val\n        ex{ @\#{ m } = val }\n      end\n    code\n  end\nend\n"