Class: String
Overview
Extends the String class with methods for system execution and output.
Instance Method Summary collapse
-
#echo ⇒ Object
Prints the string to the console, followed by a newline.
-
#exec(args = {}) ⇒ Boolean?
Executes the string as a system command.
-
#valid_name?(target = :method) ⇒ Boolean
Checks if the string is a valid Ruby method or variable name.
Instance Method Details
#echo ⇒ Object
Prints the string to the console, followed by a newline.
237 238 239 |
# File 'lib/patch/foobar.rb', line 237 def echo tap { puts self } end |
#exec(args = {}) ⇒ Boolean?
Executes the string as a system command. Allows for substituting arguments into the string using sprintf format.
232 233 234 |
# File 'lib/patch/foobar.rb', line 232 def exec(args = {}) system(self % args) end |
#valid_name?(target = :method) ⇒ Boolean
Checks if the string is a valid Ruby method or variable name.
Valid method names can include letters, numbers, underscores, and may end with ‘!`, `=`, or `?`. Valid variable names can include letters, numbers, and underscores but cannot end with `!`, `=`, or `?`.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/patch/let.rb', line 72 def valid_name?(target = :method) case target when :method self =~ /\A[a-zA-Z_]\w*[!?=]?\z/ when :var, :variable self =~ /\A[a-zA-Z_]\w*\z/ else false end end |