Class: Safer::Protocol::Match
- Inherits:
-
Object
- Object
- Safer::Protocol::Match
- Defined in:
- lib/safer/protocol.rb
Overview
Object provides an === operator, which will match when the class conforms to the protocol. Instances are not created directly by clients, but instances can be retrieved through Safer::Protocol#match_class and Safer::Protocol#match_instance.
Instance Method Summary collapse
-
#===(obj) ⇒ Object
Returns true if the object conforms to the protocol, and false if it does not.
-
#initialize(method) ⇒ Match
constructor
method
-
Method to call from owning Protocol to verify that an object matches an interface.
Constructor Details
#initialize(method) ⇒ Match
method
-
Method to call from owning Protocol to verify that an object matches an interface.
343 344 345 |
# File 'lib/safer/protocol.rb', line 343 def initialize(method) self.safer_protocol_match__method = method end |
Instance Method Details
#===(obj) ⇒ Object
Returns true if the object conforms to the protocol, and false if it does not.
350 351 352 353 354 355 356 357 |
# File 'lib/safer/protocol.rb', line 350 def ===(obj) violations = self.safer_protocol_match__method.call(obj) if violations false else true end end |