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:



470
471
472
473
# File 'lib/handshake.rb', line 470

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)


476
477
478
479
# File 'lib/handshake.rb', line 476

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

#mesgObject



480
481
482
# File 'lib/handshake.rb', line 480

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