--- !ruby/object:RI::MethodDescription
aliases:
- !ruby/object:RI::AliasName
name: open_uri_original_open
block_params:
comment:
- !ruby/struct:SM::Flow::P
body: Creates an IO object connected to the given stream, file, or subprocess.
- !ruby/struct:SM::Flow::P
body: If path does not start with a pipe character (``|''), treat it as the name of a file to open using the specified mode (defaulting to ``r''). (See the table of valid modes on page 331.) If a file is being created, its initial permissions may be set using the integer third parameter.
- !ruby/struct:SM::Flow::P
body: If a block is specified, it will be invoked with the File object as a parameter, and the file will be automatically closed when the block terminates. The call returns the value of the block.
- !ruby/struct:SM::Flow::P
body: If path starts with a pipe character, a subprocess is created, connected to the caller by a pair of pipes. The returned IO object may be used to write to the standard input and read from the standard output of this subprocess. If the command following the ``|'' is a single minus sign, Ruby forks, and this subprocess is connected to the parent. In the subprocess, the open call returns nil. If the command is not ``-'', the subprocess runs the command. If a block is associated with an open("|-") call, that block will be run twice---once in the parent and once in the child. The block parameter will be an IO object in the parent and nil in the child. The parent's IO object will be connected to the child's $stdin and $stdout. The subprocess will be terminated at the end of the block.
- !ruby/struct:SM::Flow::VERB
body: " open("testfile") do |f|\n print f.gets\n end\n"
- !ruby/struct:SM::Flow::P
body: produces:
- !ruby/struct:SM::Flow::VERB
body: " This is line one\n"
- !ruby/struct:SM::Flow::P
body: "Open a subprocess and read its output:"
- !ruby/struct:SM::Flow::VERB
body: " cmd = open("|date")\n print cmd.gets\n cmd.close\n"
- !ruby/struct:SM::Flow::P
body: produces:
- !ruby/struct:SM::Flow::VERB
body: " Wed Apr 9 08:56:31 CDT 2003\n"
- !ruby/struct:SM::Flow::P
body: "Open a subprocess running the same Ruby program:"
- !ruby/struct:SM::Flow::VERB
body: " f = open("|-", "w+")\n if f == nil\n puts "in Child"\n exit\n else\n puts "Got: #{f.gets}"\n end\n"
- !ruby/struct:SM::Flow::P
body: produces:
- !ruby/struct:SM::Flow::VERB
body: " Got: in Child\n"
- !ruby/struct:SM::Flow::P
body: "Open a subprocess using a block to receive the I/O object:"
- !ruby/struct:SM::Flow::VERB
body: " open("|-") do |f|\n if f == nil\n puts "in Child"\n else\n puts "Got: #{f.gets}"\n end\n end\n"
- !ruby/struct:SM::Flow::P
body: produces:
- !ruby/struct:SM::Flow::VERB
body: " Got: in Child\n"
full_name: Kernel#open
is_singleton: false
name: open
params: |
open(path [, mode [, perm]] ) => io or nil
open(path [, mode [, perm]] ) {|io| block } => obj
visibility: public