Class: IO

### Home Classes Methods

### In Files

- lib/backports/1.8.7/io/each_char.rb
- lib/backports/1.9.3/io/advise.rb

### Parent

Object

### Methods

- ::binread
- ::binwrite
- ::open_with_options_hash
- ::try_convert
- ::write
- #advise
- #chars
- #each_char

### Class/Module Index

Quicksearch

- Prime
- Prime::EratosthenesGenerator
- Prime::EratosthenesSieve
- Prime::Generator23
- Prime::OldCompatibility
- Prime::PseudoPrimeGenerator
- Prime::TrialDivision
- Prime::TrialDivisionGenerator
- Backports
- Backports::MOST_EXTREME_OBJECT_EVER
- Backports::Random
- Backports::Random::Implementation
- Backports::Random::MT19937
- Backports::StdLib
- Backports::StdLib::LoadedFeatures
- Enumerator
- Enumerator::GeneratorBP
- Enumerator::Lazy
- Enumerator::Yielder
- Matrix
- Matrix::EigenvalueDecomposition
- Matrix::LUPDecomposition
- Enumerable
- Enumerable::Enumerator
- File
- File::Constants
- ARGF
- Array
- BasicObject
- Bignum
- Binding
- Complex
- Dir
- ENV
- Fixnum
- Float
- GC
- Hash
- IO
- Integer
- Kernel
- Math
- Method
- Module
- NilClass
- Numeric
- Object
- ObjectSpace
- OpenStruct
- Proc
- Process
- Random
- Range
- Regexp
- Set
- StopIteration
- String
- Struct
- Symbol
- UnboundMethod

No matching classes.

# IO

### Public Class Methods

binread(file, length = nil, offset = 0) click to toggle source

    # File lib/backports/1.9.1/io/binread.rb, line 4
    def IO.binread(file, length = nil, offset = 0)
      File.open(Backports.convert_path(file),"rb") do |f|
        f.seek(offset)
        f.read(length)
      end
    end

binwrite(name, string, offset = nil, options = Backports::Undefined) click to toggle source

    # File lib/backports/1.9.3/io/binwrite.rb, line 4
    def IO.binwrite(name, string, offset = nil, options = Backports::Undefined)
      Backports.write(true, name, string, offset, options)
    end

open_with_options_hash(*args) click to toggle source

    # File lib/backports/1.9.1/io/open.rb, line 9
    def open_with_options_hash(*args)
      if args.size > 2 || args[1].respond_to?(:to_hash)
        fd, mode, options = (args << Backports::Undefined)
        args = [fd, Backports.combine_mode_and_option(mode, options)]
      end
      if block_given?
        open_without_options_hash(*args){|f| yield f}
      else
        open_without_options_hash(*args)
      end
    end

try_convert(obj) click to toggle source

    # File lib/backports/1.9.1/io/try_convert.rb, line 4
    def IO.try_convert(obj)
      Backports.try_convert(obj, IO, :to_io)
    end

write(name, string, offset = nil, options = Backports::Undefined) click to toggle source

    # File lib/backports/1.9.3/io/write.rb, line 4
    def IO.write(name, string, offset = nil, options = Backports::Undefined)
      Backports.write(false, name, string, offset, options)
    end

### Public Instance Methods

advise(advice, offset=0, len=0) click to toggle source

    # File lib/backports/1.9.3/io/advise.rb, line 5
    def advise(advice, offset=0, len=0)
      raise RangeError if Backports.coerce_to_int(offset) >= 1<<31
      raise RangeError if Backports.coerce_to_int(len) >= 1<<31
      raise IOError if closed?
      case advice
      when  :normal,
            :sequential,
            :random,
            :willneed,
            :dontneed,
            :noreuse
        return nil
      when Symbol
        raise NotImplementedError, "Unsupported advice #{advice}"
      else
        raise TypeError, "advice must be a Symbol"
      end
    end

chars() click to toggle source
Alias for: each_char
each_char() click to toggle source

    # File lib/backports/1.8.7/io/each_char.rb, line 5
    def each_char
      return to_enum(:each_char) unless block_given?
      if $KCODE == "UTF-8"
        lookup = 7.downto(4)
        while c = read(1) do
          n = c[0]
          leftmost_zero_bit = lookup.find{|i| n[i].zero? }
          case leftmost_zero_bit
          when 7 # ASCII
            yield c
          when 6 # UTF 8 complementary characters
            next # Encoding error, ignore
          else
            more = read(6-leftmost_zero_bit)
            break unless more
            yield c+more
          end
        end
      else
        while s = read(1)
          yield s
        end
      end

      self
    end

Also aliased as: chars

[Validate]

Generated with the Darkfish Rdoc Generator 2.