Top Level Namespace

Included Modules

Extended Modules

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, (LibC.isatty(2)) == 0)
STDIN = IO::FileDescriptor.new(0, blocking: (LibC.isatty(0)) == 0)
STDOUT = (IO::FileDescriptor.new(1, (LibC.isatty(1)) == 0)).tap(&.flush_on_newline = true)

Method Summary

Macro Summary

Instance methods inherited from module Spec::Expectations

be
be(value)
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

Instance methods inherited from module Spec::DSL

assert(file = __FILE__, line = __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, file = __FILE__, line = __LINE__, &block) it, pending(description, file = __FILE__, line = __LINE__, &block) pending

Method Detail

def self.`(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 *` # => "LICENSE shard.yml Readme.md spec src\n"

[View source]
def self.abort(message, status = 1) #

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


[View source]
def self.at_exit(&handler : Int32 -> ) #

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

[View source]
def self.caller #

[View source]
def self.delay(delay, &block : -> R) #

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(Process.pid) }
long_operation
d.cancel

[View source]
def self.exit(status = 0) #

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

Registered .at_exit procs are executed.


[View source]
def self.fork #

[View source]
def self.fork(&block) #

[View source]
def self.future(&exp : -> R) #

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

f = future { http_request }
... other actions ...
f.get #=> String

[View source]
def self.get_stack_top #

[View source]
def self.gets(*args) #

Reads a line from STDIN. See IO#gets.


[View source]
def self.lazy(&block : -> R) #

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) }

[View source]
def self.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

[View source]
def self.main(argc : Int32, argv : Pointer(Pointer(UInt8))) #

[View source]
def self.p(obj) #

Prints obj to STDOUT by invoking inspect(io) on it, and followed by a newline.


[View source]
def self.print(*objects : _) #

Prints objects to STDOUT and then invokes STDOUT.flush. See IO#print.


[View source]
def self.printf(format_string, args : Array | Tuple) #

Prints a formatted string to STDOUT. See IO#printf.


[View source]
def self.printf(format_string, *args) #

Prints a formatted string to STDOUT. See IO#printf.


[View source]
def self.puts(*objects) #

Prints objects to STDOUT, each followed by a newline. See IO#puts.


[View source]
def self.raise(ex : Exception) #

[View source]
def self.raise(message : String) #

[View source]
def self.rand #

see Random#rand


[View source]
def self.rand(x) #

see Random#rand(x)


[View source]
def self.read_line(*args) #

Reads a line from STDIN. See IO#read_line.


[View source]
def self.sleep #

[View source]
def self.sleep(time : Time::Span) #

[View source]
def self.sleep(seconds : Number) #

[View source]
def self.sprintf(format_string, args : Array | Tuple) : String #

Returns a formatted string. See IO#printf.


[View source]
def self.sprintf(format_string, *args) : String #

Returns a formatted string. See IO#printf.


[View source]
def self.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

[View source]
def self.with_color(color : Symbol) #

[View source]
def self.with_color #

[View source]

Macro Detail

macro assert_responds_to(var, method) #

[View source]
macro debugger #

[View source]
macro ecr_file(filename) #

[View source]
macro embed_ecr(filename, io_name) #

[View source]
macro parallel(*jobs) #

[View source]
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"]

[View source]
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"

[View source]
macro redefine_main(name = main) #

[View source]
macro spawn #

[View source]
macro spawn(exp) #

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


[View source]