Skip to content

Instantly share code, notes, and snippets.

@burtlo
Created December 8, 2010 10:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save burtlo/733131 to your computer and use it in GitHub Desktop.
Save burtlo/733131 to your computer and use it in GitHub Desktop.
Allows
$ ruby proxy.rb
Proxy Object
Customer.create
Proxy Object
Customer.create
Proxy Object
Customer.create
require 'rubygems'
require 'active_support/inflector'
module Model
class Customer
class << self
def create
puts "Customer.create"
end
module Browser
def create
puts "Customer::Browser.create"
end
end
module File
def create
puts "Customer::File.create"
end
end
end
end
end
class Customer
class << self
def method_missing(name,*params,&block)
puts "Proxy Object"
c = Class.new(Model::Customer)
c.instance_eval do
extend const_get($context) rescue self
end
c.send(name)
end
end
end
$context = "Browser"
browser = Customer.create
$context = "File"
file = Customer.create
$context = "SOAP"
soap = Customer.create
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment