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.
def assert
  raise "Assertion failed !" unless yield if $DEBUG
end

Usage :
def aFunc(i)
  assert { i < 10 }
  # ...
end

$DEBUG = true
# Ok.
aFunc(5)
# Raise Assert Exception.
aFunc(15)

$DEBUG = false
# Ok.
aFunc(5)
aFunc(15)
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS