Class: ActivePresenter::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Proxy

Returns a new instance of Proxy.

Yields:

  • (_self)

Yield Parameters:



4
5
6
7
8
9
10
11
# File 'lib/proxy.rb', line 4

def initialize(options = {}, &block)
  if options.is_a? Hash
    unless options.empty?
      options.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