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



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

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



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

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



153
154
155
156
157
# File 'lib/vendor/puppet/util/monkey_patches.rb', line 153

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