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)
-
- (Object) name
readonly
The symbolic name of the protocol.
Instance Method Summary (collapse)
-
- (Hash) class_methods
The class methods expected by this protocol.
-
- (Array) constants
The constants expected by this protocol.
-
- (Functional::ProtocolInfo) initialize(name) { ... }
constructor
Process a protocol specification block and build a new object.
-
- (Hash) instance_methods
The instance methods expected by this protocol.
-
- (Boolean) satisfies?(target)
Does the given module/class/object satisfy this protocol?.
Constructor Details
- (Functional::ProtocolInfo) initialize(name) { ... }
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
- (Object) name (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
- (Hash) class_methods
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 |
- (Array) constants
The constants expected by this protocol.
54 55 56 |
# File 'lib/functional/protocol_info.rb', line 54 def constants @info.constants end |
- (Hash) instance_methods
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 |
- (Boolean) satisfies?(target)
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 |