class IO
Public Class Methods
agrep(fd, pattern[, distance]) → anArray
click to toggle source
agrep(fd, pattern[, distance]) { |line| ... } → io
# File lib/nuggets/io/agrep.rb 35 def self.agrep(fd, pattern, distance = 0, &block) 36 open(fd) { |io| io.agrep(pattern, distance, &block) } 37 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 75 def append(name, binary = false, &block) 76 open_with_mode(name, 'a', binary, &block) 77 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 102 def append_read(name, binary = false, &block) 103 open_with_mode(name, 'a+', binary, &block) 104 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 IO::read
, not like IO::new.
# File lib/nuggets/io/modes.rb 41 def read(name, *args, **opts, &block) 42 return _nuggets_original_read(name, *args, **opts) unless block_given? 43 44 case args.size 45 when 0 46 # ok 47 when 1 48 case binary = args.first 49 when true, false, nil 50 # ok 51 else 52 raise ::TypeError, "wrong argument type #{binary.class} (expected boolean)" 53 end 54 else 55 raise ::ArgumentError, "wrong number of arguments (#{args.size + 1} for 1-2)" 56 end 57 58 open_with_mode(name, 'r', binary, &block) 59 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 84 def read_write(name, binary = false, &block) 85 open_with_mode(name, 'r+', binary, &block) 86 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 66 def write(name, binary = false, &block) 67 open_with_mode(name, 'w', binary, &block) 68 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 93 def write_read(name, binary = false, &block) 94 open_with_mode(name, 'w+', binary, &block) 95 end
Private Class Methods
open_with_mode(name, mode, binary = false, &block)
click to toggle source
Just a helper to DRY things up.
# File lib/nuggets/io/modes.rb 109 def open_with_mode(name, mode, binary = false, &block) 110 open(name, "#{mode}#{'b' if binary}", &block) 111 end