method

open

Importance_2
Ruby latest stable (v2_5_5) - 0 notes - Class: PTY
open() public

Allocates a pty (pseudo-terminal).

In the block form, yields two arguments master_io, slave_file and the value of the block is returned from open.

The IO and File are both closed after the block completes if they haven’t been already closed.

PTY.open {|master, slave|
  p master      #=> #<IO:masterpty:/dev/pts/1>
  p slave      #=> #<File:/dev/pts/1>
  p slave.path #=> "/dev/pts/1"
}

In the non-block form, returns a two element array, [master_io, slave_file].

master, slave = PTY.open
# do something with master for IO, or the slave file

The arguments in both forms are:

master_io

the master of the pty, as an IO.

slave_file

the slave of the pty, as a File. The path to the terminal device is available via slave_file.path

IO#raw! is usable to disable newline conversions:

require 'io/console'
PTY.open {|m, s|
  s.raw!
  ...
}
Show source
Register or log in to add new notes.