Class: Object

Inherits:
BasicObject
Defined in:
lib/protocol/xt.rb

Instance Method Summary collapse

Instance Method Details

#conform_to(protocol) ⇒ Object



12
13
14
# File 'lib/protocol/xt.rb', line 12

def conform_to(protocol)
  extend(protocol)
end

#conform_to?(protocol) ⇒ Boolean

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.

Returns:

  • (Boolean)


8
9
10
# File 'lib/protocol/xt.rb', line 8

def conform_to?(protocol)
  protocol.check(self)
end

#Protocol(modul = nil, &block) ⇒ Object Also known as: protocol

Define a protocol configured by block. Look at the methods of ProtocolModule to get an idea on how to do that.



18
19
20
21
22
23
24
25
# 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