Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/atk/console.rb,
lib/atk/file_sys.rb,
lib/atk/remove_indent.rb

Overview

easy access to the commandline

Instance Method Summary collapse

Instance Method Details

#-@Object

add a - operator to strings that makes it behave like a system() call but it shows stderr and returns a success value



12
13
14
15
# File 'lib/atk/console.rb', line 12

def -@
    Process.wait(Process.spawn(self))
    return $?.success?
end

#/(next_string) ⇒ Object

this is for easy creation of cross-platform filepaths ex: “foldername”/“filename”



16
17
18
19
20
21
22
23
24
25
# File 'lib/atk/file_sys.rb', line 16

def /(next_string)
    if OS.is?("windows")
        next_string_without_leading_or_trailing_slashes = next_string.gsub(/(^\\|^\/|\\$|\/$)/,"")
        output = self + "\\" + next_string
        # replace all forward slashes with backslashes
        output.gsub(/\//,"\\")
    else
        File.join(self, next_string)
    end
end

#remove_indentObject

this is for having docstrings that get their indent removed this is used frequently for multi-line strings and error messages example usage puts <<-HEREDOC.remove_indent This command does such and such.

this part is extra indented

HEREDOC



9
10
11
# File 'lib/atk/remove_indent.rb', line 9

def remove_indent
    gsub(/^[ \t]{#{self.match(/^[ \t]*/)[0].length}}/, '')
end