Module: Interface::ClassMethods
- Defined in:
- lib/interface.rb
Instance Method Summary collapse
- #implements(*modules) ⇒ Object (also: #implement)
- #interfaces ⇒ Object
- #unimplemented_methods ⇒ Object
- #unimplemented_methods_for(interface) ⇒ Object
Instance Method Details
#implements(*modules) ⇒ Object Also known as: implement
32 33 34 |
# File 'lib/interface.rb', line 32 def implements(*modules) modules.flatten.reverse!.each { |mod| include mod.extend(Abstract) } end |
#interfaces ⇒ Object
37 38 39 40 |
# File 'lib/interface.rb', line 37 def interfaces klass = is_a?(Class) ? self : self.class klass.included_modules.select { |mod| mod.is_a?(Abstract) } end |
#unimplemented_methods ⇒ Object
42 43 44 45 46 47 |
# File 'lib/interface.rb', line 42 def unimplemented_methods interfaces.inject({}) do |hash, interface| methods = unimplemented_methods_for(interface) methods.empty? ? hash : hash.merge!(interface => methods) end end |
#unimplemented_methods_for(interface) ⇒ Object
49 50 51 52 53 |
# File 'lib/interface.rb', line 49 def unimplemented_methods_for(interface) interface.instance_methods(false).reject do |method| !method_defined?(method.to_sym) || instance_method(method.to_sym).owner != interface end.sort.map(&:to_sym) end |