Module: Alda::Utils

Defined in:
lib/alda-rb/utils.rb

Overview

Some useful functions.

Class Method Summary collapse

Class Method Details

.slug_to_snake(str) ⇒ Object

:call-seq:

slug_to_snake(str) -> Symbol

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



42
43
44
# File 'lib/alda-rb/utils.rb', line 42

def slug_to_snake str
	str.to_s.gsub(?-, ?_).to_sym
end

.snake_to_slug(sym) ⇒ Object

:call-seq:

snake_to_slug(sym) -> String

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



32
33
34
# File 'lib/alda-rb/utils.rb', line 32

def snake_to_slug sym
	sym.to_s.gsub ?_, ?-
end

.warn(message) ⇒ Object

:call-seq:

warn(message) -> nil

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



12
13
14
15
# 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?Boolean

:call-seq:

win_platform? -> true or false

Returns whether the current platform is Windows.

Returns:

  • (Boolean)


22
23
24
# File 'lib/alda-rb/utils.rb', line 22

def win_platform?
	Gem.win_platform?
end