class ByteBoozer2::File
This class implements file handling related helper methods.
Attributes
data[RW]
name[RW]
Public Class Methods
load(*args)
click to toggle source
# File lib/byteboozer2/file.rb, line 8 def self.load(*args) new(*args).tap(&:read) end
new(name, data = nil)
click to toggle source
# File lib/byteboozer2/file.rb, line 16 def initialize(name, data = nil) @name = name @data = data end
save(*args)
click to toggle source
# File lib/byteboozer2/file.rb, line 12 def self.save(*args) new(*args).tap(&:write) end
Public Instance Methods
read()
click to toggle source
# File lib/byteboozer2/file.rb, line 21 def read @data = IO.binread(@name).unpack('C*') end
write()
click to toggle source
# File lib/byteboozer2/file.rb, line 25 def write ::File.open(@name, ::File::WRONLY | ::File::CREAT | ::File::EXCL, binmode: true, encoding: 'ASCII-8BIT') do |file| file.write @data.pack('C*') end end