Class: IO

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

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



174
175
176
177
178
179
# File 'lib/puppet/util/monkey_patches.rb', line 174

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



181
182
183
184
185
# File 'lib/puppet/util/monkey_patches.rb', line 181

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



168
169
170
171
172
# File 'lib/puppet/util/monkey_patches.rb', line 168

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