Class: Handshake::Invariant

Inherits:
Object
  • Object
show all
Defined in:
lib/handshake.rb

Overview

This class defines a class invariant, which has a block and an optional method. Not for external use.

Instance Method Summary collapse

Constructor Details

#initialize(mesg = nil, &block) ⇒ Invariant

:nodoc:



488
489
490
491
# File 'lib/handshake.rb', line 488

def initialize(mesg=nil, &block)
  @mesg = mesg
  @block = block
end

Instance Method Details

#holds?(o) ⇒ Boolean

Any -> Boolean Evaluates this class’s block in the binding of the given object.

Returns:

  • (Boolean)


494
495
496
497
# File 'lib/handshake.rb', line 494

def holds?(o)
  block = @block
  o.instance_eval &block
end

#mesgObject



498
499
500
# File 'lib/handshake.rb', line 498

def mesg
  @mesg || "Invariant check failed"
end