Class: Handshake::Invariant

Inherits:
Object
  • Object
show all
Defined in:
lib/handshake/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:



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

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)


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

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

#mesgObject



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

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