Class: RG::Proxy
- Inherits:
-
Object
show all
- Defined in:
- lib/rubygoods/proxy.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(mode, objs) ⇒ Proxy
Returns a new instance of Proxy.
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/rubygoods/proxy.rb', line 5
def initialize(mode, objs)
case mode
when :single
p_init_single(objs)
when :multiple
p_init_multiple(objs)
else
fail ArgumentError, "Invalid mode"
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/rubygoods/proxy.rb', line 29
def method_missing(m, *args, &block)
results = []
@objs.each do |o|
results << o.send(m, *args, &block)
end
results
end
|
Instance Attribute Details
#objs ⇒ Object
Returns the value of attribute objs.
3
4
5
|
# File 'lib/rubygoods/proxy.rb', line 3
def objs
@objs
end
|
Instance Method Details
#p_eval(dat) ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/rubygoods/proxy.rb', line 37
def p_eval(dat)
results = []
@objs.each do |o|
results << o.instance_eval(dat)
end
results
end
|
#p_init_multiple(objs) ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/rubygoods/proxy.rb', line 20
def p_init_multiple(objs)
init_single(objs) if objs.class != Array
@objs = objs
cl = @objs[0].class
@objs.each do |o|
fail(ArgumentError, "Objects' Classes are not same!") if (o.class != cl)
end
end
|
#p_init_single(obj) ⇒ Object
16
17
18
|
# File 'lib/rubygoods/proxy.rb', line 16
def p_init_single(obj)
@objs = [obj]
end
|
#p_inspect ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/rubygoods/proxy.rb', line 45
def p_inspect()
results = []
@objs.each do |o|
results << o.inspect
end
results
end
|