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 <<-code
def #{ m } *a, &b
#{ to }.#{ m } *a, &b
end
code
end
end
|
#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 <<-code
def #{ m }(*a, &b)
if a.empty?
sh{ @#{ m } }
else
self.#{ m }= a.shift
end
end
alias_method '#{ m }?', '#{ m }'
def #{ m }= val
ex{ @#{ m } = val }
end
code
end
end
|