Class: Toy::Proxies::Proxy
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/toy/proxies/proxy.rb
Direct Known Subclasses
List
Instance Method Summary
collapse
Constructor Details
#initialize(list, owner) ⇒ Proxy
Returns a new instance of Proxy.
16
17
18
19
|
# File 'lib/toy/proxies/proxy.rb', line 16
def initialize(list, owner)
@list, @owner = list, owner
list.extensions.each { |extension| proxy_extend(extension) }
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
55
56
57
|
# File 'lib/toy/proxies/proxy.rb', line 55
def method_missing(method, *args, &block)
target.send(method, *args, &block)
end
|
Instance Method Details
#assert_type(record) ⇒ Object
39
40
41
42
43
|
# File 'lib/toy/proxies/proxy.rb', line 39
def assert_type(record)
unless record.is_a?(proxy_class)
raise(ArgumentError, "#{proxy_class} expected, but was #{record.class}")
end
end
|
25
26
27
|
# File 'lib/toy/proxies/proxy.rb', line 25
def each
target.each { |i| yield(i) }
end
|
#eql?(other) ⇒ Boolean
Also known as:
==
29
30
31
|
# File 'lib/toy/proxies/proxy.rb', line 29
def eql?(other)
target == other
end
|
#proxy_owner ⇒ Object
21
22
23
|
# File 'lib/toy/proxies/proxy.rb', line 21
def proxy_owner
@owner
end
|
#proxy_respond_to? ⇒ Object
11
|
# File 'lib/toy/proxies/proxy.rb', line 11
alias :proxy_respond_to? :respond_to?
|
#respond_to?(*args) ⇒ Boolean
45
46
47
|
# File 'lib/toy/proxies/proxy.rb', line 45
def respond_to?(*args)
proxy_respond_to?(*args) || target.respond_to?(*args)
end
|
#target ⇒ Object
Also known as:
to_a
34
35
36
|
# File 'lib/toy/proxies/proxy.rb', line 34
def target
@target ||= find_target
end
|