Skip to main content
Version: v0.20.0

Array

a = [1, 2, 3, 4, 5]
puts(a[2])
puts(a[-2])
puts(a[:2])
puts(a[:-2])
puts(a[2:])
puts(a[-2:])
puts(a[1:-2])

// should output
[1, 2]
[1, 2, 3]
[3, 4, 5]
[4, 5]
[2, 3]
[1, 2, 8, 9, 5]

Literal Specific Methodsโ€‹

first()โ€‹

Returns STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FUNCTION|FILE

Returns the first element of the array. Shorthand for array[0]

๐Ÿš€ > ["a", "b", 1, 2].first()
=> "a"

index(STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FILE)โ€‹

Returns INTEGER

Returns the index of the given element in the array if found. Otherwise return -1.

๐Ÿš€ > ["a", "b", 1, 2].index(1)
=> 2

last()โ€‹

Returns STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FUNCTION|FILE

Returns the last element of the array.

๐Ÿš€ > ["a", "b", 1, 2].last()
=> 2

reverse()โ€‹

Returns ARRAY

Reverses the elements of the array

๐Ÿš€ > ["a", "b", 1, 2].reverse()
=> [2, 1, "b", "a"]

size()โ€‹

Returns INTEGER

Returns the amount of elements in the array.

๐Ÿš€ > ["a", "b", 1, 2].size()
=> 4

sort()โ€‹

Returns ARRAY

Sorts the array if it contains only one type of STRING, INTEGER or FLOAT

๐Ÿš€ ยป [3.4, 3.1, 2.0].sort()
ยป [2.0, 3.1, 3.4]

uniq()โ€‹

Returns ARRAY|ERROR

Returns a copy of the array with deduplicated elements. Raises an error if a element is not hashable.

๐Ÿš€ > ["a", 1, 1, 2].uniq()
=> [1, 2, "a"]

yeet()โ€‹

Returns STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FUNCTION|FILE

Removes the last element of the array and returns it.

๐Ÿš€ > a = [1,2,3]
=> [1, 2, 3]
๐Ÿš€ > a.yeet()
=> 3
๐Ÿš€ > a
=> [1, 2]

yoink(STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FUNCTION|FILE)โ€‹

Returns NIL

Adds the given object as last element to the array.

๐Ÿš€ > a = [1,2,3]
=> [1, 2, 3]
๐Ÿš€ > a.yoink("a")
=> nil
๐Ÿš€ > a
=> [1, 2, 3, "a"]

Generic Literal Methodsโ€‹

methods()โ€‹

Returns ARRAY

Returns an array of all supported methods names.

๐Ÿš€ > "test".methods()
=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase]

to_json()โ€‹

Returns STRING|ERROR

Returns the object as json notation.

๐Ÿš€ > a = {"test": 1234}
=> {"test": 1234}
๐Ÿš€ > a.to_json()
=> "{"test":1234}"

type()โ€‹

Returns STRING

Returns the type of the object.

๐Ÿš€ > "test".type()
=> "STRING"

wat()โ€‹

Returns STRING

Returns the supported methods with usage information.

๐Ÿš€ > true.wat()
=> BOOLEAN supports the following methods:
plz_s()