class IO

Public Class Methods

_nuggets_original_read(name, *args)
Alias for: read
agrep(fd, pattern[, distance]) → anArray click to toggle source
agrep(fd, pattern[, distance]) { |line| ... } → io
# File lib/nuggets/io/agrep.rb, line 35
def self.agrep(fd, pattern, distance = 0, &block)
  open(fd) { |io| io.agrep(pattern, distance, &block) }
end
append(name[, binary]) → anIO click to toggle source
append(name[, binary]) { |io| ... } → anObject

Opens name with mode a.

# File lib/nuggets/io/modes.rb, line 75
def append(name, binary = false)
  open_with_mode(name, 'a', binary, &block_given? ? ::Proc.new : nil)
end
append_read(name[, binary]) → anIO click to toggle source
append_read(name[, binary]) { |io| ... } → anObject

Opens name with mode a+.

# File lib/nuggets/io/modes.rb, line 102
def append_read(name, binary = false)
  open_with_mode(name, 'a+', binary, &block_given? ? ::Proc.new : nil)
end
read(name[, length[, offset]]]) → aString click to toggle source
read(name[, binary]) { |io| ... } → anObject

Opens name with mode r. NOTE: With no associated block, acts like the original ::read, not like IO::new.

# File lib/nuggets/io/modes.rb, line 41
def read(name, *args)
  return _nuggets_original_read(name, *args) unless block_given?

  case args.size
    when 0
      # ok
    when 1
      case binary = args.first
        when true, false, nil
          # ok
        else
          raise ::TypeError, "wrong argument type #{binary.class} (expected boolean)"
      end
    else
      raise ::ArgumentError, "wrong number of arguments (#{args.size + 1} for 1-2)"
  end

  open_with_mode(name, 'r', binary, &::Proc.new)
end
Also aliased as: _nuggets_original_read
read_write(name[, binary]) → anIO click to toggle source
read_write(name[, binary]) { |io| ... } → anObject

Opens name with mode r+.

# File lib/nuggets/io/modes.rb, line 84
def read_write(name, binary = false)
  open_with_mode(name, 'r+', binary, &block_given? ? ::Proc.new : nil)
end
write(name[, binary]) → anIO click to toggle source
write(name[, binary]) { |io| ... } → anObject

Opens name with mode w.

# File lib/nuggets/io/modes.rb, line 66
def write(name, binary = false)
  open_with_mode(name, 'w', binary, &block_given? ? ::Proc.new : nil)
end
write_read(name[, binary]) → anIO click to toggle source
write_read(name[, binary]) { |io| ... } → anObject

Opens name with mode w+.

# File lib/nuggets/io/modes.rb, line 93
def write_read(name, binary = false)
  open_with_mode(name, 'w+', binary, &block_given? ? ::Proc.new : nil)
end

Private Class Methods

open_with_mode(name, mode, binary = false) click to toggle source

Just a helper to DRY things up.

# File lib/nuggets/io/modes.rb, line 109
def open_with_mode(name, mode, binary = false)
  open(name, "#{mode}#{'b' if binary}", &block_given? ? ::Proc.new : nil)
end