| Module | LazyMethods::InstanceMethods |
| In: |
lib/lazy_methods.rb
|
# File lib/lazy_methods.rb, line 7 7: def self.included (base) 8: base.alias_method_chain :method_missing, :lazy 9: end
Override missing method to add the lazy method handling
# File lib/lazy_methods.rb, line 12
12: def method_missing_with_lazy (method, *args, &block)
13: if method.to_s[0, 5] == 'lazy_'
14: method = method.to_s
15: return Proxy.new(self, method[5, method.length].to_sym, args, &block)
16: else
17: # Keep track of the current missing method calls to keep out of an infinite loop
18: stack = Thread.current[:lazy_method_missing_methods] ||= []
19: sig = MethodSignature.new(self, method)
20: raise NoMethodError.new("undefined method `#{method}' for #{self}") if stack.include?(sig)
21: begin
22: stack.push(sig)
23: return method_missing_without_lazy(method, *args, &block)
24: ensure
25: stack.pop
26: end
27: end
28: end