Module ImplIOO
In: lib/ioo.rb

With this class you can easily overwrite only write or read methods to change the whole IO.

This is very usefull to produce a crypted IO for example.

Methods

<<   each   each_byte   each_line   getc   gets   print   printf   putc   puts   readchar   readline   readlines  

Public Instance methods

[Source]

# File lib/ioo.rb, line 16
  def << ( obj )
    write obj
    self
  end

[Source]

# File lib/ioo.rb, line 21
  def each ( sep_string=$/, &block )
    begin
      loop { block[readline(sep_string)] }
    rescue EOFError
      return self
    end
  end

[Source]

# File lib/ioo.rb, line 30
  def each_byte ( &block )
    begin
      loop { block[readchar] }
    rescue EOFError
      return nil
    end
  end
each_line( sep_string=$/, &block )

Alias for each

[Source]

# File lib/ioo.rb, line 38
  def getc
    begin
      readchar
    rescue EOFError
      nil
    end
  end

[Source]

# File lib/ioo.rb, line 46
  def gets ( sep_string=$/ )
    begin
      readline(sep_string)
    rescue EOFError
      nil
    end
  end

[Source]

# File lib/ioo.rb, line 54
  def print ( *args )
    if args.empty?
      write $_
    else
      args.each { |x| write x }
    end
    nil
  end

[Source]

# File lib/ioo.rb, line 63
  def printf ( fmt, *args )
    write Kernel.sprintf(fmt, *args)
    nil
  end

[Source]

# File lib/ioo.rb, line 68
  def putc ( c )
    case c
    when Numeric then write c.chr
    when String
      if c.size == 1
        write c
      else
        c = c[0].chr
        write c
      end
    else
      c = c.to_s[0].chr
      write c
    end
    c
  end

[Source]

# File lib/ioo.rb, line 85
  def puts ( *args )
    if args.size == 0
      write "\n"
    else
      args.each do |x|
        x = x.to_s
        write x
        write "\n" unless x[-1] == ?\n
      end
    end
    nil
  end

[Source]

# File lib/ioo.rb, line 98
  def readchar
    raise EOFError if eof?
    read(1)[0]
  end

[Source]

# File lib/ioo.rb, line 103
  def readline ( sep_string=$/ )
    raise EOFError if eof?
    buf = ''
    begin
      while (char = readchar) != ?\n
        buf += char.chr
      end
      return buf + char.chr
    rescue EOFError
      return buf
    end
  end

[Source]

# File lib/ioo.rb, line 116
  def readlines ( sep_string=$/ )
    res = []
    each_line(sep_string) { |line| res << line }
    res
  end

[Validate]