Console::Str
console 0.2.0 · app/console/str.rb · 145 lines · view source
Console::Str -- string helpers that avoid Regexp.
mruby (the VM DragonRuby embeds) does not ship with the Regexp class, so none of the standard regular-expression methods are available. Everything in the console therefore uses these plain-string helpers instead.
def chop(str, suffix)-
Remove a trailing suffix if present: chop('.rb', 'hello.rb') -> 'hello'
def split_on(str, chars)-
Split on any of the characters in
chars.String#split treats its argument as a literal separator, so passing '-_' would split on that exact two-character sequence rather than on either character. Splits per character instead.
def lines(str)-
Split into lines.
def digits?(str)-
True when every character of
stris a decimal digit and str is not empty. Replaces the /\A\d+\z/ idiom. def quoted_value_after(str, prefix)-
Find the value of a quoted constant assignment, e.g. title_of('TITLE = "Hello"') -> 'Hello'.
Written with explicit length-based slicing rather than ranges, because mruby's String#[] with a computed Range endpoint is not dependable.
def after_at(s, n)-
s[n, s.length - n] without Range indexing.
def chomp_slash(str)-
Drop trailing slashes: chomp_slash('carts/space/') -> 'carts/space'
def basename(str)-
The last segment of a path: basename('carts/space') -> 'space'
A cart's directory doubles as its name, so this is what turns a path back into the module a cart is expected to define.
def capitalize(str)-
Uppercase the first character: capitalize('hello') -> 'Hello'
def camel(str)-
'hello-world' -> 'HelloWorld'
def snake(str)-
'HelloWorld' -> 'hello_world'
def fit(str, width)-
Pad/truncate to exactly
widthcharacters. def blank?(str)- line 141