Class: IO

Inherits:
Object show all
Defined in:
lib/vendor/puppet/util/monkey_patches.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.binread(name, length = nil, offset = 0) ⇒ Object



165
166
167
168
169
170
# File 'lib/vendor/puppet/util/monkey_patches.rb', line 165

def self.binread(name, length = nil, offset = 0)
  File.open(name, 'rb') do |f|
    f.seek(offset) if offset > 0
    f.read(length)
  end
end

.binwrite(name, string, offset = 0) ⇒ Object



172
173
174
175
176
# File 'lib/vendor/puppet/util/monkey_patches.rb', line 172

def self.binwrite(name, string, offset = 0)
  File.open(name, 'wb') do |f|
    f.write(offset > 0 ? string[offset..-1] : string)
  end
end

Instance Method Details

#lines(separator = $/) ⇒ Object



159
160
161
162
163
# File 'lib/vendor/puppet/util/monkey_patches.rb', line 159

def lines(separator = $/)
  lines = split(separator)
  block_given? and lines.each {|line| yield line }
  lines
end