Top Level Namespace

Defined in:

Macro Summary

Macro Detail

macro guard(value, &block) #

Simple macro for guarding against nil/false values. Concept taken from Swift. If the guard block is omitted, it will call return. If a block is passed in, it will be called if the vaue is nil or false, and must include a return, next break, or raise.

Example:

def normalize(value : Int32?)
  guard value do
    return 0
  end

  value
end

normalize(1)   # => 1
normalize(nil) # => 0

[View source]