module MethodNotMissing
Constants
- VERSION
Public Class Methods
included(base)
click to toggle source
# File lib/method_not_missing.rb, line 8 def self.included (base) base.extend self end
Public Instance Methods
const_missing(name)
click to toggle source
# File lib/method_not_missing.rb, line 51 def const_missing(name) puts "Missing class #{name}" puts "making it up on the spot" klass = Class.new(OmnipotentObject) const_set(name, klass) klass end
method_missing(meth, *args) { || ... }
click to toggle source
Calls superclass method
# File lib/method_not_missing.rb, line 12 def method_missing (meth, *args) result = nil puts "Missing: #{meth}" args.each { |arg| arg.extend MethodNotMissing rescue nil } found = MethodSearcher.search_method(meth.to_s).detect do |method_body| begin puts "*"*80 puts method_body puts "*"*80 vars = method_body.scan(/@[a-zA-Z0-9_]+/) puts "Vars: #{vars}" vars.each do |var| # We want a class with << because that's a common method and # it can't be found online. object = Class.new(Array) { include MethodNotMissing }.new instance_variable_get(var) or instance_variable_set(var, object) end self.class.send(:eval, method_body) result = self.send(meth, *args) do yield end true rescue Exception => e # We wanna rescue stack overflows also puts "Error!" puts e.inspect false end end if found result else super end end