Top Level Namespace

Included Modules

Spec::DSL, Spec::Expectations

Extended Modules

Spec::DSL, Spec::Expectations

Defined in:

Constant Summary

Method Summary

Macro Summary

Method Detail

def self.`(command)

def self.abort(message, status = 1)

Terminates execution immediately, printing message to STDERR and then calling .exit(status).


def self.at_exit(&handler : -> )

Registers the given Proc for execution when the program exits. If multiple handlers are registered, they are executed in reverse order of registration.

def do_at_exit(str1)
  at_exit { print str1 }
end

at_exit { puts "cruel world" }
do_at_exit("goodbye ")
exit

Produces:

goodbye cruel world

def self.caller

def self.exit(status = 0)

Terminates execution immediately, returning the given status code to the invoking environment.

Registered .at_exit procs are executed.


def self.fork(&block)

def self.fork

def self.get_stack_top

def self.gets(*args)

def self.loop(&block)

Repeatedly executes the block.

loop do
  print "Input: "
  line = gets
  break unless line
  # ...
end

def self.main(argc : Int32, argv : Pointer(Pointer(UInt8)))

def self.p(obj)

def self.print(*objects : _)

def self.print!(*objects : _)

def self.printf(format_string, args : Array | Tuple)

def self.printf(format_string, *args)

def self.puts(*objects)

def self.raise(message : String)

def self.raise(ex : Exception)

def self.rand

def self.rand(x)

def self.read_line(*args)

def self.sleep(seconds : Int | Float)

def self.sprintf(format_string, *args)

def self.sprintf(format_string, args : Array | Tuple)

def self.system(command : String)

def self.with_color

def self.with_color(color : Symbol)

Macro Detail

macro assert_responds_to(var, method)

macro debugger

macro parallel(*jobs)

macro pp(*exps)

Prints a series of expressions together with their values. Useful for print style debugging.

a = 1
pp a # prints "a = 1"

pp [1, 2, 3].map(&.to_s) # prints "[1, 2, 3].map(&.to_s) = ["1", "2", "3"]

macro record(name, *properties)

Defines a struct with the given name and properties.

The generated struct has a constructor with the given properties in the same order as declared. The struct only provides getters, not setters, making it immutable by default.

You can pass a block to this macro, that will be inserted inside the struct definition.

record Point, x, y

point = Point.new 1, 2
point.to_s #=> "Point(@x=1, @y=2)"

An example with the block version:

record Person, first_name, last_name do
  def full_name
    "#{first_name} #{last_name}"
  end
end

person = Person.new "John", "Doe"
person.full_name #=> "John Doe"

macro redefine_main(name = main)

macro spawn

macro spawn(exp)

TODO: this doesn't work if a Call has a block or named arguments... yet