--- !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 <tt>IO</tt> object connected to the given stream, file, or subprocess.
- !ruby/struct:SM::Flow::P 
  body: If <em>path</em> does not start with a pipe character (``<tt>|</tt>''), treat it as the name of a file to open using the specified mode (defaulting to ``<tt>r</tt>''). (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 <tt>File</tt> 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 <em>path</em> starts with a pipe character, a subprocess is created, connected to the caller by a pair of pipes. The returned <tt>IO</tt> object may be used to write to the standard input and read from the standard output of this subprocess. If the command following the ``<tt>|</tt>'' is a single minus sign, Ruby forks, and this subprocess is connected to the parent. In the subprocess, the <tt>open</tt> call returns <tt>nil</tt>. If the command is not ``<tt>-</tt>'', the subprocess runs the command. If a block is associated with an <tt>open(&quot;|-&quot;)</tt> call, that block will be run twice---once in the parent and once in the child. The block parameter will be an <tt>IO</tt> object in the parent and <tt>nil</tt> in the child. The parent's <tt>IO</tt> object will be connected to the child's <tt>$stdin</tt> and <tt>$stdout</tt>. The subprocess will be terminated at the end of the block.
- !ruby/struct:SM::Flow::VERB 
  body: "   open(&quot;testfile&quot;) do |f|\n     print f.gets\n   end\n"
- !ruby/struct:SM::Flow::P 
  body: <em>produces:</em>
- !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(&quot;|date&quot;)\n   print cmd.gets\n   cmd.close\n"
- !ruby/struct:SM::Flow::P 
  body: <em>produces:</em>
- !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(&quot;|-&quot;, &quot;w+&quot;)\n   if f == nil\n     puts &quot;in Child&quot;\n     exit\n   else\n     puts &quot;Got: #{f.gets}&quot;\n   end\n"
- !ruby/struct:SM::Flow::P 
  body: <em>produces:</em>
- !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(&quot;|-&quot;) do |f|\n     if f == nil\n       puts &quot;in Child&quot;\n     else\n       puts &quot;Got: #{f.gets}&quot;\n     end\n   end\n"
- !ruby/struct:SM::Flow::P 
  body: <em>produces:</em>
- !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
