Discord

Preparing your files

Please wait until the download is ready.

Luka's Scripting Utilities

Luka's Scripting Utilities

by Luka S.J.

A pack full of various scripting utilities to ease your development!

v4.1.135,194
Download144 KB

Ruby Object Extensions

LUTS adds a set of convenience methods to the Ruby built-in classes. The most
widely used are the blank? / present? predicates, which are defined
consistently across Array, Hash, String, Numeric, Symbol and
NilClass so you can test "emptiness" uniformly regardless of type.

Array

  • array.swap_at(index1, index2) swaps the values at two indexes
  • array.to_last(val) moves a value to the end of the array (removing it from its current position first)
  • array.last?(index) checks whether the given index is the last index
  • array.string_include?(val) checks whether any string element is contained within the given string
  • array.value(index) fetches the element at the given index
  • array.blank? true when the array has no elements
  • array.present? true when the array has any elements

Hash

  • hash.value(key) returns the value for the given key
  • hash.merge_many(*hashes) merges multiple hashes into self
  • hash.blank? true when the hash has no keys
  • hash.present? true when the hash has any keys

String

Constants & casing

  • string.constantize resolves the string to a Ruby constant (object)
  • string.safe_constantize resolves to a constant, or nil if it does not exist
  • string.capitalize capitalises the first letter
  • string.camelize converts an under_scored string to CamelCase
  • string.underscore converts a CamelCased string to snake_case
  • string.demodulize strips leading module namespaces from a constant name
  • string.preposition returns the indefinite article ("a" or "an") for the string
  • string.blank? true when the string is empty or only whitespace
  • string.present? true when the string has non-whitespace content

Console colour tags

These wrap the string in colour markup for console output:

string.red · string.green · string.blue ·
string.cyan · string.magenta · string.yellow ·
string.purple · string.orange

Numeric

  • number.lerp(inverse: false) scales the number for frame-rate-independent interpolation
  • number.blank? true when the value is zero
  • number.present? true when the value is non-zero

Frame-count helpers convert a count into the equivalent number of 60-FPS frames
(singular forms are aliases of the plural):

  • number.minute / number.minutes
  • number.hour / number.hours
  • number.day / number.days
# wait two in-game minutes (in frames)
2.minutes   # => 7200

Symbol & NilClass

For interface consistency with the other types:

  • symbol.blank? always false, symbol.present? always true
  • nil.blank? always true, nil.present? always false