6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/interface.rb', line 6
def self.extended(interface)
interface.class_eval do
instance_methods(false).each do |method|
define_method(method) do |*args, &block|
methods = [:super, :method_missing]
begin
send(methods.shift, *args, &block)
rescue NoMethodError
if methods.empty?
raise NotImplementedError.new("#{self.class} needs to implement '#{method}' for interface #{interface}")
else
args.unshift(method.to_sym)
retry
end
end
end
end
end
end
|