Class: ActivePresenter::Proxy
Instance Method Summary collapse
- #create_method(name, &block) ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Proxy
constructor
A new instance of Proxy.
- #method_missing(sym, *args) ⇒ Object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Proxy
Returns a new instance of Proxy.
4 5 6 7 8 9 10 11 |
# File 'lib/proxy.rb', line 4 def initialize( = {}, &block) if .is_a? Hash unless .empty? .each_pair {|k,v| self.send("#{k}=", v)} end end yield self if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/proxy.rb', line 13 def method_missing(sym, *args) syms = sym.to_s if syms.match(/.=$/) key = syms.chop gen_methods(key) self.send("#{key}=", args.from_args) else key = sym.to_s gen_methods(key) self.send("#{key}", args.from_args) end end |
Instance Method Details
#create_method(name, &block) ⇒ Object
27 28 29 |
# File 'lib/proxy.rb', line 27 def create_method(name, &block) self.class.send(:define_method, name, &block) end |