class Object
Constants
- Comparing
Protocol
version of the Comparable module, that actually checks, if <=> was implemented by the including (conforming) class.- Enumerating
Protocol
version of the Enumerable module, that actually checks, if each was implemented by the including (conforming) class.- Indexing
Checks if indexing behaviour exists as in Array or Hash.
- Synchronizing
Public Instance Methods
Protocol(modul = nil, &block)
click to toggle source
Define a protocol configured by block
. Look at the methods of ProtocolModule to get an idea on how to do that.
# File lib/protocol/xt.rb, line 18 def Protocol(modul = nil, &block) pm = ProtocolModule.new(&block) if modul pm.infer(modul) else pm end end
Also aliased as: protocol
conform_to(protocol)
click to toggle source
# File lib/protocol/xt.rb, line 12 def conform_to(protocol) extend(protocol) end
conform_to?(protocol)
click to toggle source
Returns true if this object conforms to protocol
, otherwise false.
This is especially useful, if check_failure in the protocol is set to :none or :warning, and conformance of a class to a protocol should be checked later in runtime.
# File lib/protocol/xt.rb, line 8 def conform_to?(protocol) protocol.check(self) end