Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Olivier

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Basic ruby assert function

A very simple way to add assert capability to function.
   1  
   2  def assert
   3    raise "Assertion failed !" unless yield if $DEBUG
   4  end

Usage :
   1  
   2  def aFunc(i)
   3    assert { i < 10 }
   4    # ...
   5  end
   6  
   7  $DEBUG = true
   8  # Ok.
   9  aFunc(5)
  10  # Raise Assert Exception.
  11  aFunc(15)
  12  
  13  $DEBUG = false
  14  # Ok.
  15  aFunc(5)
  16  aFunc(15)
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS