30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/delegate_missing_to.rb', line 30
def delegate_missing_to(*object_names)
object_names.reverse_each do |object_name|
define_method "method_missing_with_delegation_to_#{object_name}" do |method, *args, &block|
object = send(object_name)
if object.respond_to?(method)
object.public_send(method, *args, &block)
else
send("method_missing_without_delegation_to_#{object_name}", method, *args, &block)
end
end
alias_method_chain :method_missing, "delegation_to_#{object_name}"
end
end
|