Module: CloseCall
- Included in:
- T
- Defined in:
- lib/carat-dev/closecall/closecall.rb
Constant Summary collapse
- MIN_SCORE =
0.75
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/carat-dev/closecall/closecall.rb', line 63 def method_missing(symbol, *args) puts "Finding method for #{symbol} with #{args.length} args" sym = find_similar_symbol(symbol, args.length) if sym != nil method = method(sym) max_arity = self.public_methods.collect{|sym| self.method(sym).arity}.sort.last if !self.respond_to?(symbol) code = %' def #{symbol}(*args) case args.length' 0.upto(max_arity) do |x| sym = find_similar_symbol(symbol, x); if (sym != nil) code += %' when #{x} if block_given? #{sym}(*args) { |*bargs| yield *bargs } else #{sym}(*args) end' end end code = code + %' else raise NameError, "no method similar to \'#{symbol}\' found for \#{args.length} args" end end' #puts code puts "defining method for #{symbol}" self.class.class_eval code end return self.send(symbol, *args) { |*| yield * } end raise NameError, "no method similar to `#{symbol}' with #{args.length} args for \"#{self}\":#{self.class}" end |