美文网首页Ruby on Rails
How to Use The Kernel Open Metho

How to Use The Kernel Open Metho

作者: jackli0855 | 来源:发表于2020-09-03 15:04 被阅读0次

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 Metho

    本文链接:https://www.haomeiwen.com/subject/ugtosktx.html