- README

- Top Level Namespace
- Adler32
- ArgumentError
- Array
- Atomic
- Base64
  - Error
- Benchmark
  - BM
    - Job
    - Tms
  - IPS
    - Entry
    - Job
- BigFloat
- BigInt
- BigRational
- BitArray
- Bool
- Box
- Bytes
- Channel
  - Buffered
  - ClosedError
  - ReceiveAction
  - SelectAction
  - SendAction
  - Unbuffered
- Char
  - Reader
- Class
- Colorize
  - Object
  - ObjectExtensions
- Comparable
- Complex
- Concurrent
  - CanceledError
- CRC32
- Crypto
  - Bcrypt
    - Error
    - Password
  - Blowfish
  - Subtle
- Crystal
  - Macros
    - And
    - Arg
    - ArrayLiteral
    - Assign
    - ASTNode
    - BinaryOp
    - Block
    - BoolLiteral
    - Call
    - Case
    - Cast
    - CharLiteral
    - ClassDef
    - ClassVar
    - Def
    - Expressions
    - Generic
    - Global
    - HashLiteral
    - If
    - ImplicitObj
    - InstanceSizeOf
    - InstanceVar
    - IsA
    - Macro
    - MacroId
    - MetaVar
    - MultiAssign
    - NamedArgument
    - NamedTupleLiteral
    - NilableCast
    - NilLiteral
    - Nop
    - Not
    - NumberLiteral
    - Or
    - Out
    - Path
    - PointerOf
    - RangeLiteral
    - ReadInstanceVar
    - RegexLiteral
    - Require
    - RespondsTo
    - SizeOf
    - Splat
    - StringInterpolation
    - StringLiteral
    - SymbolLiteral
    - TupleLiteral
    - TypeDeclaration
    - TypeNode
    - UnaryExpression
    - UninitializedVar
    - Union
    - Var
    - VisibilityModifier
    - When
    - While
  - System
- CSV
  - Builder
    - Row
  - Error
  - Lexer
  - MalformedCSVError
  - Parser
  - Row
  - Token
    - Kind
- Debug
  - DWARF
    - Abbrev
      - Attribute
    - AT
    - FORM
    - Info
      - Value
    - LineNumbers
      - Register
      - Row
      - Sequence
    - LNE
    - LNS
    - Strings
    - TAG
  - ELF
    - Endianness
    - Error
    - Ident
    - Klass
    - Machine
    - OSABI
    - SectionHeader
      - Flags
      - Type
    - Type
- Deque
- Digest
  - Base
  - MD5
  - SHA1
- Dir
- DivisionByZero
- DL
- ECR
- Enum
- Enumerable
  - EmptyError
- ENV
- Errno
- Exception
- Fiber
- File
  - Stat
- FileUtils
- Flate
  - Error
  - Reader
  - Strategy
  - Writer
- Float
  - Primitive
  - Printer
    - CachedPowers
      - Power
    - DiyFP
    - Grisu3
    - IEEE
- Float32
- Float64
- GC
  - Stats
- Gzip
  - Error
  - Header
  - Reader
  - Writer
- Hash
- HTML
- HTTP
  - Client
    - BodyType
    - Response
  - CompressHandler
  - ComputedContentTypeHeader
  - Cookie
  - Cookies
  - ErrorHandler
  - FormData
    - Builder
    - Error
    - FileMetadata
    - Parser
    - Part
  - Handler
    - Proc
  - Headers
  - LogHandler
  - Multipart
    - Builder
    - Error
    - Parser
  - Params
    - Builder
  - Request
  - Server
    - Context
    - RequestProcessor
    - Response
  - StaticFileHandler
    - DirectoryListing
  - WebSocket
  - WebSocketHandler
- Indexable
- IndexError
- INI
- Int
  - Primitive
  - Signed
  - Unsigned
- Int16
- Int32
- Int64
- Int8
- InvalidByteSequenceError
- IO
  - Buffered
  - ByteFormat
    - BigEndian
    - LittleEndian
    - NetworkEndian
    - SystemEndian
  - Delimited
  - EncodingOptions
  - EOFError
  - Error
  - FileDescriptor
  - Hexdump
  - Memory
  - MultiWriter
  - Seek
  - Sized
  - Timeout
- IPSocket
- Iterable
- Iterator
  - IteratorWrapper
  - Stop
- JSON
  - Any
  - Builder
    - ArrayState
    - DocumentEndState
    - DocumentStartState
    - ObjectState
    - StartState
    - State
  - Error
  - Lexer
  - ParseException
  - Parser
  - PullParser
  - Token
  - Type
- KeyError
- Levenshtein
  - Finder
- LLVM
  - ABI
    - AArch64
    - ArgKind
    - ArgType
    - ARM
    - FunctionType
    - X86
    - X86_64
      - RegClass
  - AtomicOrdering
  - AtomicRMWBinOp
  - Attribute
  - AttributeIndex
  - BasicBlock
  - BasicBlockCollection
  - Builder
  - CallConvention
  - CodeGenFileType
  - CodeGenOptLevel
  - CodeModel
  - Context
  - DIBuilder
  - DIFlags
  - DwarfTag
  - DwarfTypeEncoding
  - Function
  - FunctionCollection
  - FunctionPassManager
    - Runner
  - GenericValue
  - GlobalCollection
  - InstructionCollection
  - IntPredicate
  - JITCompiler
  - Linkage
  - MemoryBuffer
  - Module
  - ModuleFlag
  - ModulePassManager
  - OperandBundleDef
  - ParameterCollection
  - PassManagerBuilder
  - PassRegistry
  - PhiTable
  - RealPredicate
  - RelocMode
  - Target
  - TargetData
  - TargetMachine
  - Type
    - Kind
  - Value
    - Kind
  - ValueMethods
  - VerifierFailureAction
- Logger
  - Formatter
  - Severity
- Markdown
  - HTMLRenderer
  - Parser
    - PrefixHeader
    - UnorderedList
  - Renderer
- Math
- Mutex
- NamedTuple
- Nil
- Number
  - Primitive
- OAuth
  - AccessToken
  - Consumer
  - Error
  - RequestToken
- OAuth2
  - AccessToken
    - Bearer
    - Mac
  - Client
  - Error
  - Session
- Object
- OpenSSL
  - Digest
    - Error
    - UnsupportedError
  - DigestBase
  - DigestIO
    - DigestMode
  - Error
  - HMAC
  - MD5
  - SHA1
  - SSL
    - Context
      - Client
      - Server
    - Error
    - ErrorType
    - Modes
    - Options
    - Socket
      - Client
      - Server
    - VerifyMode
    - X509VerifyFlags
- OptionParser
  - Exception
  - InvalidOption
  - MissingOption
- PartialComparable
- Pointer
  - Appender
- PrettyPrint
- Proc
- Process
  - Env
  - Status
  - Stdio
  - Tms
- Random
  - ISAAC
  - MT19937
  - PCG32
  - System
- Range
- Readline
  - CompletionProc
  - KeyBindingProc
- Reference
- Reflect
- Regex
  - MatchData
  - Options
- SecureRandom
- Set
- Signal
- Slice
- Socket
  - Address
  - Addrinfo
  - Error
  - Family
  - IPAddress
  - Protocol
  - Server
  - Type
  - UNIXAddress
- Spec
  - Expectations
  - Methods
  - ObjectExtensions
- StaticArray
- String
  - Builder
  - RawConverter
- StringPool
- StringScanner
- Struct
- Symbol
- System
- TCPServer
- TCPSocket
- Tempfile
- Termios
  - AttributeSelection
  - BaudRate
  - ControlMode
  - InputMode
  - LineControl
  - LocalMode
  - OutputMode
- Time
  - DayOfWeek
  - EpochConverter
  - EpochMillisConverter
  - Format
    - Error
  - Kind
  - MonthSpan
  - Span
- Tuple
- TypeCastError
- UDPSocket
- UInt16
- UInt32
- UInt64
- UInt8
- Unicode
  - CaseOptions
- Union
- UNIXServer
- UNIXSocket
- URI
  - Error
- Value
- WeakRef
- XML
  - Attributes
  - AttributeType
  - Builder
  - Error
  - HTMLParserOptions
  - Namespace
  - Node
  - NodeSet
  - ParserOptions
  - Reader
  - SaveOptions
  - Type
  - XPathContext
- YAML
  - Any
  - Builder
  - Error
  - EventKind
  - ParseException
  - Parser
  - PullParser
  - Type
- Zip
  - CompressionMethod
  - Error
  - File
    - Entry
  - FileInfo
  - Reader
    - Entry
  - Writer
    - Entry
- Zlib
  - Error
  - Reader
  - Writer

# Top Level Namespace

## Included Modules

- Spec::Expectations
- Spec::Methods

## Extended Modules

- Spec::Expectations
- Spec::Methods

## Defined in:

## Constant Summary

ARGF = `IO::ARGF.new(ARGV, STDIN)`
ARGV = `((ARGV_UNSAFE + 1).to_slice(ARGC_UNSAFE - 1)).map do |c_str| String.new(c_str) end`
PROGRAM_NAME = `String.new(ARGV_UNSAFE.value)`
STDERR = `(IO::FileDescriptor.new(2, blocking: (LibC.isatty(2)) == 0)).tap do |f| f.flush_on_newline = true end`
STDIN = `IO::FileDescriptor.new(0, blocking: (LibC.isatty(0)) == 0)`
STDOUT = `(IO::FileDescriptor.new(1, blocking: (LibC.isatty(1)) == 0)).tap do |f| f.flush_on_newline = true end`

## Method Summary

- `(command) : String

  Returns the standard output of executing command in a subshell.

- abort(message, status = 1) : NoReturn

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

- at_exit(&handler : Int32 -> ) : Nil

  Registers the given `Proc` for execution when the program exits.

- caller
- delay(delay, &block : -> _)

  Spawns a `Fiber` to compute &block in the background after delay has elapsed.

- exit(status = 0) : NoReturn

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

- fork

  See also: `Process.fork`

- fork(&block)

  See also: `Process.fork`

- future(&exp : -> _)

  Spawns a `Fiber` to compute &block in the background.

- gets(*args, **options)

  Reads a line from `STDIN`.

- lazy(&block : -> _)

  Conditionally spawns a `Fiber` to run &block in the background.

- loop(&block)

  Repeatedly executes the block, passing an incremental `Int32` that starts with `0`.

- p(*objects)

  Pretty prints each object in objects to `STDOUT`, followed by a newline.

- p

  Pretty prints each object in objects to `STDOUT`, followed by a newline.

- p(object)

  Pretty prints object to `STDOUT` followed by a newline.

- print(*objects : _) : Nil

  Prints objects to STDOUT and then invokes `STDOUT.flush`.

- printf(format_string, args : Array | Tuple) : Nil

  Prints a formatted string to `STDOUT`.

- printf(format_string, *args) : Nil

  Prints a formatted string to `STDOUT`.

- puts(*objects) : Nil

  Prints objects to `STDOUT`, each followed by a newline.

- raise(exception : Exception) : NoReturn

  Raises the exception.

- raise(message : String) : NoReturn

  Raises an Exception with the message.

- rand(x)

  See `Random#rand(x)`.

- rand

  See `Random#rand`.

- read_line(*args, **options)

  Reads a line from `STDIN`.

- sleep

  Blocks the current fiber forever.

- sleep(time : Time::Span)

  Blocks the current Fiber for the specified time span.

- sleep(seconds : Number)

  Blocks the current fiber for the specified number of seconds.

- spawn(*, name : String? = nil, &block)

  Spawns a new fiber.

- sprintf(format_string, *args) : String

  Returns a formatted string.

- sprintf(format_string, args : Array | Tuple) : String

  Returns a formatted string.

- system(command : String, args = nil) : Bool

  Executes the given command in a subshell.

- with_color(color : Symbol)
- with_color

## Macro Summary

- assert_responds_to(var, method)
- debugger
- parallel(*jobs)
- pp(*exps)

  Prints a series of expressions together with their values.

- record(name, *properties)

  Defines a `Struct` with the given name and properties.

- redefine_main(name = main)
- spawn(call, *, name = nil)

  Spawns a fiber by first creating a `Proc`, passing the call's expressions to it, and letting the `Proc` finally invoke the call.

### Instance methods inherited from module `Spec::Methods`

assert(file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block) assert, context(description, file = __FILE__, line = __LINE__, &block) context, describe(description, file = __FILE__, line = __LINE__, &block) describe, fail(msg, file = __FILE__, line = __LINE__) fail, it(description = "assert", file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block) it, pending(description = "assert", file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block) pending

### Instance methods inherited from module `Spec::Expectations`

be(value)
be be, be_close(expected, delta) be_close, be_false be_false, be_falsey be_falsey, be_nil be_nil, be_true be_true, be_truthy be_truthy, contain(expected) contain, eq(value) eq, match(value) match

## Method Detail

def `(command) : String #

Returns the standard output of executing command in a subshell. Standard input, and error are inherited. The special `$?` variable is set to a `Process::Status` associated with this execution.

Example:

    `echo hi` # => "hi\n"

def abort(message, status = 1) : NoReturn #

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

def at_exit(&handler : Int32 -> ) : Nil #

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 caller #
def delay(delay, &block : -> _) #

Spawns a `Fiber` to compute &block in the background after delay has elapsed. Access to get is synchronized between fibers. &block is only called once. May be canceled before &block is called by calling `cancel`.

    d = delay(1) { Process.kill(Signal::KILL, Process.pid) }
    # ... long operations ...
    d.cancel

def exit(status = 0) : NoReturn #

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

Registered `at_exit` procs are executed.

def fork #

See also: `Process.fork`

def fork(&block) #

See also: `Process.fork`

def future(&exp : -> _) #

Spawns a `Fiber` to compute &block in the background. Access to get is synchronized between fibers. &block is only called once.

    f = future { `echo hello` }
    # ... other actions ...
    f.get # => "hello\n"

def gets(*args, **options) #

Reads a line from `STDIN`.

See also: `IO#gets`.

def lazy(&block : -> _) #

Conditionally spawns a `Fiber` to run &block in the background. Access to get is synchronized between fibers. &block is only called once. &block doesn't run by default, only when `get` is called.

    l = lazy { expensive_computation }
    spawn { maybe_use_computation(l) }
    spawn { maybe_use_computation(l) }

def loop(&block) #

Repeatedly executes the block, passing an incremental `Int32` that starts with `0`.

    loop do |i|
      print "#{i}) "
      line = gets
      break unless line
      # ...
    end

def p(*objects) #

Pretty prints each object in objects to `STDOUT`, followed by a newline. Returns objects.

See also: `Object#pretty_print(pp)`.

def p #

Pretty prints each object in objects to `STDOUT`, followed by a newline. Returns objects.

    p foo: 23, bar: 42 # => {foo: 23, bar: 42}

See `Object#pretty_print(pp)`

def p(object) #

Pretty prints object to `STDOUT` followed by a newline. Returns object.

See also: `Object#pretty_print(pp)`.

def print(*objects : _) : Nil #

Prints objects to STDOUT and then invokes `STDOUT.flush`.

See also: `IO#print`.

def printf(format_string, args : Array | Tuple) : Nil #

Prints a formatted string to `STDOUT`.

See also: `IO#printf`.

def printf(format_string, *args) : Nil #

Prints a formatted string to `STDOUT`.

See also: `IO#printf`.

def puts(*objects) : Nil #

Prints objects to `STDOUT`, each followed by a newline.

See also: `IO#puts`.

def raise(exception : Exception) : NoReturn #

Raises the exception.

This will set the exception's callstack if it hasn't been already. Re-raising a previously catched exception won't replace the callstack.

def raise(message : String) : NoReturn #

Raises an Exception with the message.

def rand(x) #

See `Random#rand(x)`.

def rand #

See `Random#rand`.

def read_line(*args, **options) #

Reads a line from `STDIN`.

See also: `IO#read_line`.

def sleep #

Blocks the current fiber forever.

Meanwhile, other ready-to-execute fibers might start their execution.

def sleep(time : Time::Span) #

Blocks the current Fiber for the specified time span.

While this fiber is waiting this time other ready-to-execute fibers might start their execution.

def sleep(seconds : Number) #

Blocks the current fiber for the specified number of seconds.

While this fiber is waiting this time other ready-to-execute fibers might start their execution.

def spawn(*, name : String? = nil, &block) #

Spawns a new fiber.

The newly created fiber doesn't run as soon as spawned.

Example:

    # Write "1" every 1 second and "2" every 2 seconds for 6 seconds.

    ch = Channel(Nil).new

    spawn do
      6.times do
        sleep 1
        puts 1
      end
      ch.send(nil)
    end

    spawn do
      3.times do
        sleep 2
        puts 2
      end
      ch.send(nil)
    end

    2.times { ch.receive }

def sprintf(format_string, *args) : String #

Returns a formatted string.

See also: `IO#printf`.

def sprintf(format_string, args : Array | Tuple) : String #

Returns a formatted string.

See also: `IO#printf`.

def system(command : String, args = nil) : Bool #

Executes the given command in a subshell. Standard input, output and error are inherited. Returns `true` if the command gives zero exit code, `false` otherwise. The special `$?` variable is set to a `Process::Status` associated with this execution.

If command contains no spaces and args is given, it will become its argument list.

If command contains spaces and args is given, command must include `"${@}"` (including the quotes) to receive the argument list.

No shell interpretation is done in args.

Example:

    system("echo *")

Produces:

    LICENSE shard.yml Readme.md spec src

def with_color(color : Symbol) #
def with_color #

## 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 # => "a # => 1"

    pp [1, 2, 3].map(&.to_s) # => "[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.

The properties can be type declarations or assignments.

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

    record Point, x : Int32, y : Int32

    Point.new 1, 2 # => #<Point(@x=1, @y=2)>

An example with the block version:

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

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

An example with type declarations and default values:

    record Point, x : Int32 = 0, y : Int32 = 0

    Point.new      # => #<Point(@x=0, @y=0)>
    Point.new y: 2 # => #<Point(@x=0, @y=2)>

An example with assignments (in this case the compiler must be able to infer the types from the default values):

    record Point, x = 0, y = 0

    Point.new      # => #<Point(@x=0, @y=0)>
    Point.new y: 2 # => #<Point(@x=0, @y=2)>

macro redefine_main(name = main) #
macro spawn(call, *, name = nil) #

Spawns a fiber by first creating a `Proc`, passing the call's expressions to it, and letting the `Proc` finally invoke the call.

Compare this:

    i = 0
    while i < 5
      spawn { print(i) }
      i += 1
    end
    Fiber.yield
    # Output: 55555

To this:

    i = 0
    while i < 5
      spawn print(i)
      i += 1
    end
    Fiber.yield
    # Output: 01234

This is because in the first case all spawned fibers refer to the same local variable, while in the second example copies of i are passed to a `Proc` that eventually invokes the call.