Skip to content

Kernel

class Amethyst::Kernel

The public static methods of Amethyst::Kernel can be called anywhere without a receiver or an import. The class is marked AmethystLibrary. To add your own globally available methods, see Extending the Kernel.

def puts(value: Any): Void
def puts: Void

Writes value followed by a newline. Strings are written as-is; anything else is converted with to_s, which writes nil as an empty string and true as True. With no argument, writes an empty line.

def print(value: Any): Void

Like puts, without the trailing newline.

def p(value: Any): Void

Writes value.inspect: strings in double quotes with escapes, characters in single quotes, nil as nil, and arrays and hashes as [1, 2] and {"a" => 1}.

def pp(value: Any): Void

Like p. Formatting nested collections across multiple lines is not implemented yet.

def rand(n: Int): Int
def rand: Float

A random integer from 0 up to, but not including, n. With no argument, a random Float from 0.0 up to, but not including, 1.0.

def sleep(seconds: Float): Void

Pauses the current thread for seconds.

The ObjectExtensions class adds these to every type:

Signature Description
to_s: String The string form puts and string interpolation use.
inspect: String The representation p writes.
responds_to?(name: Symbol): Bool Whether the object has a public instance method or property called name, under its Amethyst or .NET name.
send(name: Symbol, *args: Any?): Any? Calls the member called name by reflection and returns its result.

The compiler calls these from the code it emits. They are public so that emitted code can reach them, and aren’t meant to be called directly:

Method Purpose
Kernel.ToS(value), Kernel.Inspect(value) The implementations of to_s and inspect.
Kernel.Interpolate(parts) Joins the parts of an interpolated string.
Kernel.CaseEquals(pattern, value) The match test for case/when when the subject’s type is Any.
Dynamic.FindMember(type, name), Dynamic.Invoke(target, name, args) The reflection lookup behind responds_to? and send.