4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/params_ready/extensions/delegation.rb', line 4
def self.delegate(mod, &to)
mod.define_method :method_missing do |name, *args, &block|
delegee = instance_eval(&to)
if delegee.respond_to? name
delegee.send name, *args, &block
else
super name, *args, &block
end
end
mod.send(:ruby2_keywords, :method_missing)
mod.define_method :respond_to_missing? do |name, include_private = false|
delegee = instance_eval(&to)
if delegee.respond_to? name
true
else
super name, include_private
end
end
end
|