class Object

Public Instance Methods

method_missing(meth, *args, &block) click to toggle source
Calls superclass method
# File lib/feeling_lucky.rb, line 53
def method_missing(meth, *args, &block)
  all_methods = self.methods + self.singleton_methods
  meth_str    = meth.to_s
  threshold   = threshold(meth_str)
  good_methods = all_methods.select {|word| Levenshtein.distance(meth_str, word.to_s) <= threshold }
  if good_methods.length > 0
    puts "#{self.class}:: for #{meth} picked #{good_methods.first}"
    begin
      self.send(good_methods.first, *args, &block)
    rescue Exception => e
      super
    end
  else
    super
  end
end
threshold(word) click to toggle source
# File lib/feeling_lucky.rb, line 48
def threshold(word)
  (word.size * 0.3).ceil
end