module Alda::Utils

Some useful functions.

Public Class Methods

slug_to_snake(str) → Symbol click to toggle source

Converts a slug-case String to a snake_case Symbol. The inverse of ::snake_to_slug.

# File lib/alda-rb/utils.rb, line 42
def slug_to_snake str
  str.to_s.gsub(?-, ?_).to_sym
end
snake_to_slug(sym) → String click to toggle source

Converts a snake_case Symbol to a slug-case String. The inverse of ::slug_to_snake.

# File lib/alda-rb/utils.rb, line 32
def snake_to_slug sym
  sym.to_s.gsub ?_, ?-
end
warn(message) → nil click to toggle source

Prints a warning message to standard error, appended by a newline. The message is prefixed with the filename and lineno of the caller (the lowest level where the file is not an alda-rb source file).

# File lib/alda-rb/utils.rb, line 12
def warn message
  location = caller_locations.find { !_1.path.start_with? __dir__ }
  Warning.warn "#{location.path}:#{location.lineno}: #{message}\n"
end
win_platform? → true or false click to toggle source

Returns whether the current platform is Windows.

# File lib/alda-rb/utils.rb, line 22
def win_platform?
  Gem.win_platform?
end