Module: Interface::Abstract

Defined in:
lib/interface/abstract.rb

Overview

When extended, this module will re-define an interface’s methods to raise NotImplementedError when called (unless handled by method_missing)

Class Method Summary collapse

Class Method Details

.extended(interface) ⇒ Object

:nodoc:



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/interface/abstract.rb', line 4

def self.extended(interface) # :nodoc:
  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