Class: Bossy::Interface
- Inherits:
-
Object
- Object
- Bossy::Interface
- Defined in:
- lib/bossy/interface.rb
Instance Attribute Summary collapse
-
#interface_methods ⇒ Object
Returns the value of attribute interface_methods.
-
#klass ⇒ Object
Returns the value of attribute klass.
Instance Method Summary collapse
- #add_required_methods(m) ⇒ Object
-
#initialize(klass, required_methods) ⇒ Interface
constructor
A new instance of Interface.
- #print ⇒ Object
- #to_s ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(klass, required_methods) ⇒ Interface
Returns a new instance of Interface.
5 6 7 8 9 |
# File 'lib/bossy/interface.rb', line 5 def initialize(klass, required_methods) @klass = klass @interface_methods = [] add_required_methods(required_methods) end |
Instance Attribute Details
#interface_methods ⇒ Object
Returns the value of attribute interface_methods.
3 4 5 |
# File 'lib/bossy/interface.rb', line 3 def interface_methods @interface_methods end |
#klass ⇒ Object
Returns the value of attribute klass.
3 4 5 |
# File 'lib/bossy/interface.rb', line 3 def klass @klass end |
Instance Method Details
#add_required_methods(m) ⇒ Object
21 22 23 |
# File 'lib/bossy/interface.rb', line 21 def add_required_methods(m) @interface_methods += m end |
#print ⇒ Object
32 33 34 |
# File 'lib/bossy/interface.rb', line 32 def print puts to_s end |
#to_s ⇒ Object
25 26 27 28 29 30 |
# File 'lib/bossy/interface.rb', line 25 def to_s bullet = "\u279E".encode s = "Interface for #{@klass}\n" s += interface_methods.map{|m| "#{bullet} #{m}" }.join("\n") return s end |
#validate! ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/bossy/interface.rb', line 11 def validate! interface_methods.each do |method_signature| unless class_has_method?(klass, method_signature.name) raise Bossy::Errors::MethodMissing, "Please define #{klass}##{method_signature.name} with the signature:\n\n#{method_signature}\n\n" end end return true end |