Module: Interface
- Defined in:
- lib/interface.rb,
lib/interface/version.rb,
lib/interface/abstract.rb
Overview
Implementable interfaces in ruby
Defined Under Namespace
Instance Method Summary collapse
-
#implements(*modules) ⇒ Object
(also: #implement)
Takes a module (or multiple in reverse order), extends it with
Interface::Abstract
, then includes it into the current object. -
#interfaces ⇒ Object
Returns an array of interfaces implemented by the current object.
Instance Method Details
#implements(*modules) ⇒ Object Also known as: implement
Takes a module (or multiple in reverse order), extends it with Interface::Abstract
, then includes it into the current object
Example
module Remote
# turns the device on
def on
end
end
class Device
implements Remote
def on
@power = true
end
end
23 24 25 |
# File 'lib/interface.rb', line 23 def implements(*modules) modules.flatten.reverse!.each { |mod| include mod.extend(Abstract) } end |
#interfaces ⇒ Object
Returns an array of interfaces implemented by the current object
31 32 33 |
# File 'lib/interface.rb', line 31 def interfaces included_modules.select { |mod| mod.is_a?(Abstract) } end |