module AbstractInterface::SingletonMethods

Public Instance Methods

implements(interface, &block) click to toggle source
# File lib/ruby_us/abstract_interface.rb, line 46
def implements interface, &block
  interface_instance = Interface.new self, interface
  interface.module_eval do
    block.call interface_instance
  end if block_given?
end
needs_implement_method(method_name) click to toggle source
# File lib/ruby_us/abstract_interface.rb, line 53
def needs_implement_method method_name
  interface = self.name
  define_method method_name do |*args|
    exception_message interface, method_name
  end
end
needs_implement_singleton_method(method_name) click to toggle source
# File lib/ruby_us/abstract_interface.rb, line 60
def needs_implement_singleton_method method_name
  self.module_eval do
    interface_name = self.name
    constant = self::SingletonMethods
    constant.module_eval do
      define_method method_name do |*args|
        singleton_exception_message interface_name, method_name
      end
    end
  end
end

Private Instance Methods

exception_message(interface, method_name) click to toggle source
# File lib/ruby_us/abstract_interface.rb, line 73
def exception_message interface, method_name
  constant = self.is_a?(Module) ? self : self.class
  raise NotImplementedError, "#{constant} needs to implement '#{method_name}' method of interface #{interface}"
end
singleton_exception_message(interface, method_name) click to toggle source
# File lib/ruby_us/abstract_interface.rb, line 78
def singleton_exception_message interface, method_name
  constant = self.is_a?(Module) ? self : self.class
  raise NotImplementedError, "#{constant} needs to implement '#{method_name}' singleton method of interface #{interface}"
end