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.
771 772 773 |
# File 'lib/utils/irb.rb', line 771 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.
754 755 756 757 758 759 760 |
# File 'lib/utils/irb.rb', line 754 def |(cmd) IO.popen(cmd, 'w+') do |f| f.write self f.close_write return f.read end end |