How to Use The Kernel Open Method

Ruby has a very flexible open method.

It allows you to open files & read data from a URL, and even open pipes to run external commands.

Example:

open "abc.txt"

That's why this method is to be avoided.

It's a security risk that it can do all these things.

Instead, it's better to use the specific open method that you need.

Example:

File.open           # File
IO.popen            # Process open
URI.parse(...).open # URL open

All of these return an IO object.

Summary

You've learned about input/output in Ruby! You've learned about file descriptors, the IO class, buffering, reading in chunks & standard IO streams.

ruby-io-mindmap.png

你可能感兴趣的:(How to Use The Kernel Open Method)