Created
December 8, 2010 10:48
-
-
Save burtlo/733131 to your computer and use it in GitHub Desktop.
Allows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby proxy.rb | |
Proxy Object | |
Customer.create | |
Proxy Object | |
Customer.create | |
Proxy Object | |
Customer.create |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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