Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active August 29, 2015 14:19
Show Gist options
  • Save rightfold/f44a8c7f783b63cd5d30 to your computer and use it in GitHub Desktop.
Save rightfold/f44a8c7f783b63cd5d30 to your computer and use it in GitHub Desktop.
PreconditionViolation <- subclass Error {
constructor { |this.|
this.name := "PreconditionViolation"
this.message := "precondition violation"
stackFrames <- (new Error).stack.split "\n"
stackFrames.splice 1 3
this.stack := stackFrames.join "\n"
}
}
require <- { |condition|
if (! condition) { throw: new PreconditionViolation }
}
fib <- { |n|
require: >= n 0
if (< n 2) {1} { + (fib: - n 1) (fib: - n 2) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment