new
 
  new(*args)
  public
  Returns a new IO object (a stream) for the given IO object or integer file descriptor and mode string. See also IO#fileno and IO.for_fd.
Parameters
| fd | numeric file descriptor | 
| mode | file mode. a string or an integer | 
| opt | hash for specifiying mode by name. | 
Mode
When mode is an integer it must be combination of the modes defined in File::Constants.
When mode is a string it must be in one of the following forms:
- 
“fmode”, 
- 
“fmode:extern”, 
- 
“fmode:extern:intern”. 
extern is the external encoding name for the IO. intern is the internal encoding. fmode must be combination of the directives. See the description of class IO for a description of the directives.
Options
opt can have the following keys
| :mode | same as mode parameter | 
| external encoding for the IO. “-” is a synonym for the default external encoding. | |
| internal encoding for the IO. “-” is a synonym for the default internal encoding. If the value is nil no conversion occurs. | |
| :encoding | specifies external and internal encodings as “extern:intern”. | 
| :textmode | If the value is truth value, same as “b” in argument mode. | 
| If the value is truth value, same as “t” in argument mode. | 
Also opt can have same keys in String#encode for controlling conversion between the external encoding and the internal encoding.
Example1
a = IO.new(2,"w") # '2' is standard error $stderr.puts "Hello" a.puts "World"
produces:
Hello World
Example2
io = IO.new(2, mode: 'w:UTF-16LE', cr_newline: true) io.puts "Hello, World!" io = IO.new(2, mode: 'w', cr_newline: true, external_encoding: Encoding::UTF_16LE) io.puts "Hello, World!"
both of aboves print “Hello, World!” in UTF-16LE to standard error output with converting EOL generated by puts to CR.

 RSpec
RSpec Ruby on Rails
Ruby on Rails Ruby
Ruby 
   
   
   
   
    
 
   = protected
 = protected
  