Class: Functional::ProtocolInfo
- Inherits:
-
Synchronization::Object
- Object
- Synchronization::Object
- Functional::ProtocolInfo
- Defined in:
- lib/functional/protocol_info.rb
Overview
An immutable object describing a single protocol and capable of building itself from a block. Used by #SpecifyProtocol.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The symbolic name of the protocol.
Instance Method Summary collapse
-
#class_methods ⇒ Hash
The class methods expected by this protocol.
-
#constants ⇒ Array
The constants expected by this protocol.
-
#initialize(name) { ... } ⇒ Functional::ProtocolInfo
constructor
Process a protocol specification block and build a new object.
-
#instance_methods ⇒ Hash
The instance methods expected by this protocol.
-
#satisfies?(target) ⇒ Boolean
Does the given module/class/object satisfy this protocol?.
Constructor Details
#initialize(name) { ... } ⇒ Functional::ProtocolInfo
Process a protocol specification block and build a new object.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/functional/protocol_info.rb', line 22 def initialize(name, &specification) raise ArgumentError.new('no block given') unless block_given? raise ArgumentError.new('no name given') if name.nil? || name.empty? super @name = name.to_sym @info = Info.new({}, {}, []) self.instance_eval(&specification) @info.each_pair{|col, _| col.freeze} @info.freeze ensure_ivar_visibility! self.freeze end |
Instance Attribute Details
#name ⇒ Object (readonly)
The symbolic name of the protocol
12 13 14 |
# File 'lib/functional/protocol_info.rb', line 12 def name @name end |
Instance Method Details
#class_methods ⇒ Hash
The class methods expected by this protocol.
47 48 49 |
# File 'lib/functional/protocol_info.rb', line 47 def class_methods @info.class_methods end |
#constants ⇒ Array
The constants expected by this protocol.
54 55 56 |
# File 'lib/functional/protocol_info.rb', line 54 def constants @info.constants end |
#instance_methods ⇒ Hash
The instance methods expected by this protocol.
39 40 41 |
# File 'lib/functional/protocol_info.rb', line 39 def instance_methods @info.instance_methods end |
#satisfies?(target) ⇒ Boolean
Does the given module/class/object satisfy this protocol?
61 62 63 64 65 |
# File 'lib/functional/protocol_info.rb', line 61 def satisfies?(target) satisfies_constants?(target) && satisfies_instance_methods?(target) && satisfies_class_methods?(target) end |