Sha256: 34d5c72c9567c54284e95c52df985a356e26ec9541b4d34cab074b3a10170340

Contents?: true

Size: 647 Bytes

Versions: 2

Compression:

Stored size: 647 Bytes

Contents

module Interface
  # When extended, this abstract interface will re-define an object's methods to raise <tt>NotImplementedError</tt> when called (unless handled by <tt>method_missing</tt>)
  module Abstract
    def self.extended(base) # :nodoc:
      base.class_eval do
        instance_methods(false).each do |method|
          define_method(method) do |*args|
            begin
              method_missing(method.to_sym, *args)
            rescue NoMethodError
              raise NotImplementedError.new("#{self.class} needs to implement '#{method}' for interface #{base}")
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shuber-interface-0.0.2 lib/interface/abstract.rb
shuber-interface-0.0.1 lib/interface/abstract.rb