Module: Utils::IRB::String

Included in:
String
Defined in:
lib/utils/irb.rb

Instance Method Summary collapse

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.

Parameters:

  • filename (String)

    the path to the file where the string content will be written

Returns:

  • (Integer)

    the number of bytes written to the file



721
722
723
# File 'lib/utils/irb.rb', line 721

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.

Parameters:

  • cmd (String)

    the shell command to execute

Returns:

  • (String)

    the output of the executed command



704
705
706
707
708
709
710
# File 'lib/utils/irb.rb', line 704

def |(cmd)
  IO.popen(cmd, 'w+') do |f|
    f.write self
    f.close_write
    return f.read
  end
end