-
-
Save anonymous/dd7ddb6e301ba18caa1a to your computer and use it in GitHub Desktop.
kind of a proxy - relay . an adapter
This file contains 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
class Foo | |
attr_reader :a, :b | |
def initialize params={} | |
params.each { | |
|k,v| | |
instance_variable_set "@#{k}", v | |
} | |
end | |
def yay; puts "Yay"; end | |
end | |
class FooProxy | |
attr_accessor :foo | |
def initialize(params={}) | |
@foo = params["foo"] || Foo.new(params) | |
end | |
def method_missing(meth, *args, &bl) | |
if @foo.respond_to?(meth); @foo.send(meth);else; puts "#{meth} does_not exist";end | |
end | |
end | |
#### main | |
p = FooProxy.new(a: 1, b: 2) | |
%w{a b yay}.each{ | |
|meth| p.send(meth) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment