Class: IO

Inherits:
Object show all
Extended by:
Nuggets::IO::InteractMixin
Includes:
Nuggets::IO::RedirectMixin
Defined in:
lib/nuggets/io/modes.rb,
lib/nuggets/io/agrep.rb,
lib/nuggets/io/interact.rb,
lib/nuggets/io/redirect.rb

Overview

--

                                                                        #

nuggets -- Extending Ruby # # Copyright (C) 2007-2011 Jens Wille # # Authors: # Jens Wille [email protected] # # nuggets is free software; you can redistribute it and/or modify it under # the terms of the GNU Affero General Public License as published by the Free # Software Foundation; either version 3 of the License, or (at your option) # any later version. # # nuggets is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for # more details. # # You should have received a copy of the GNU Affero General Public License # along with nuggets. If not, see http://www.gnu.org/licenses/. # #

++

Class Method Summary collapse

Methods included from Nuggets::IO::InteractMixin

interact

Methods included from Nuggets::IO::RedirectMixin

#redirect

Class Method Details

._nuggets_original_readObject



33
# File 'lib/nuggets/io/modes.rb', line 33

alias_method :_nuggets_original_read, :read

.agrep(fd, pattern, distance = 0, &block) ⇒ Object

call-seq:

IO.agrep(fd, pattern[, distance]) -> anArray
IO.agrep(fd, pattern[, distance]) { |line| ... } -> io


35
36
37
# 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 = false, &block) ⇒ Object

call-seq:

IO.append(name[, binary]) => anIO
IO.append(name[, binary]) { |io| ... } => anObject

Opens name with mode a.



75
76
77
# File 'lib/nuggets/io/modes.rb', line 75

def append(name, binary = false, &block)
  open_with_mode(name, 'a', binary, &block)
end

.append_read(name, binary = false, &block) ⇒ Object

call-seq:

IO.append_read(name[, binary]) => anIO
IO.append_read(name[, binary]) { |io| ... } => anObject

Opens name with mode a+.



102
103
104
# File 'lib/nuggets/io/modes.rb', line 102

def append_read(name, binary = false, &block)
  open_with_mode(name, 'a+', binary, &block)
end

.read(name, *args, **opts, &block) ⇒ Object

call-seq:

IO.read(name[, length[, offset]]]) => aString
IO.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.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/nuggets/io/modes.rb', line 41

def read(name, *args, **opts, &block)
  return _nuggets_original_read(name, *args, **opts) 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, &block)
end

.read_write(name, binary = false, &block) ⇒ Object

call-seq:

IO.read_write(name[, binary]) => anIO
IO.read_write(name[, binary]) { |io| ... } => anObject

Opens name with mode r+.



84
85
86
# File 'lib/nuggets/io/modes.rb', line 84

def read_write(name, binary = false, &block)
  open_with_mode(name, 'r+', binary, &block)
end

.write(name, binary = false, &block) ⇒ Object

call-seq:

IO.write(name[, binary]) => anIO
IO.write(name[, binary]) { |io| ... } => anObject

Opens name with mode w.



66
67
68
# File 'lib/nuggets/io/modes.rb', line 66

def write(name, binary = false, &block)
  open_with_mode(name, 'w', binary, &block)
end

.write_read(name, binary = false, &block) ⇒ Object

call-seq:

IO.write_read(name[, binary]) => anIO
IO.write_read(name[, binary]) { |io| ... } => anObject

Opens name with mode w+.



93
94
95
# File 'lib/nuggets/io/modes.rb', line 93

def write_read(name, binary = false, &block)
  open_with_mode(name, 'w+', binary, &block)
end