Module: Utils::IRB::String
- Included in:
- String
- Defined in:
- lib/utils/irb.rb
Overview
A module that extends String with additional utility methods for shell command piping and file writing operations.
Provides convenient methods for executing shell commands on string content and securely writing strings to files.
Instance Method Summary collapse
-
#>>(filename) ⇒ Integer
The >> method writes the string content to a file securely.
-
#|(cmd) ⇒ String
The | method executes a shell command and returns its output.
Instance Method Details
#>>(filename) ⇒ Integer
The >> method writes the string content to a file securely.
This method takes a filename and uses File.secure_write to write the string’s content to that file, ensuring secure file handling practices are followed.
858 859 860 |
# File 'lib/utils/irb.rb', line 858 def >>(filename) File.secure_write(filename, self) end |
#|(cmd) ⇒ String
The | method executes a shell command and returns its output.
This method takes a command string, pipes the current string to it via stdin, captures the command’s stdout, and returns the resulting output as a string.
841 842 843 844 845 846 847 |
# File 'lib/utils/irb.rb', line 841 def |(cmd) IO.popen(cmd, 'w+') do |f| f.write self f.close_write return f.read end end |