Class: Safer::Protocol::Match

Inherits:
Object
  • Object
show all
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

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