This module provides most of the basic input and output functions of IO objects as implemented in Ruby version 1.8.7. Its use is supported on all versions of Ruby. See the general documentation of IO::Like for a description of how to create a class capable of using this module.
Include this module explicitly rather than IO::Like if the including class should always behave like Ruby 1.8.7 IO no matter what version of Ruby is running the class.
Returns self. Just for compatibility with IO.
# File lib/io/like-1.8.7.rb, line 21 def binmode raise IOError, 'closed stream' if closed? self end
Calls each_byte without a block and returns the resulting Enumerable::Enumerator instance.
# File lib/io/like-1.8.7.rb, line 31 def bytes each_byte end
chars is just an alias for eachchar in Ruby 1.8.7.
Reads each byte (0..255) from the stream using getbyte and calls the given block once for each byte, passing the byte as an argument.
NOTE: This method ignores Errno::EAGAIN and Errno::EINTR raised by unbuffered_read. Therefore, this method always blocks. Aside from that exception and the conversion of EOFError results into nil results, this method will also raise the same errors and block at the same times as unbuffered_read.
# File lib/io/like-1.8.7.rb, line 48 def each_byte(&b) block_given? ? super(&b) : Enumerable::Enumerator.new(self, :each_byte) end
Reads each character from the stream and calls the given block once for each character, passing the character as an argument. The character is a single or multi-byte string depending on the character to be read and the setting of $KCODE.
When called without a block, returns an instance of Enumerable::Enumerator which will iterate over each character in the same manner.
NOTE: This method ignores Errno::EAGAIN and Errno::EINTR raised by unbuffered_read. Therefore, this method always blocks. Aside from that exception and the conversion of EOFError results into nil results, this method will also raise the same errors and block at the same times as unbuffered_read.
# File lib/io/like-1.8.7.rb, line 73 def each_char unless block_given? then return Enumerable::Enumerator.new(self, :each_char) end while (byte = getbyte) do char = byte.chr # The first byte of the character was already read, so read 1 less than # the total number of bytes for the character to get the rest. __io_like__char_len(byte).downto(2) do byte = getbyte break if byte.nil? char << byte.chr end yield(char) end self end
Reads each line from the stream using gets and calls the given block once for each line, passing the line as an argument.
When called without a block, returns an instance of Enumerable::Enumerator which will iterate over each line in the same manner.
NOTE: When sep_string is not nil, this method ignores Errno::EAGAIN and Errno::EINTR raised by unbuffered_read. Therefore, this method always blocks. Aside from that exception and the conversion of EOFError results into nil results, this method will also raise the same errors and block at the same times as unbuffered_read.
# File lib/io/like-1.8.7.rb, line 114 def each_line(sep_string = $/, &b) block_given? ? super(sep_string, &b) : Enumerable::Enumerator.new(self, :each_line, sep_string) end
Calls each_line without a block and returns the resulting Enumerable::Enumerator instance.
# File lib/io/like-1.8.7.rb, line 129 def lines(sep_string = $/) each_line(sep_string) end
Generated with the Darkfish Rdoc Generator 2.