Module: XRay::Helper::FileReader
Instance Method Summary collapse
-
#readfile(path, opt = {}) ⇒ Object
auto detect file encoding and read it.
Instance Method Details
#readfile(path, opt = {}) ⇒ Object
auto detect file encoding and read it. return with an array containing string and encoding
11 12 13 14 15 16 17 18 |
# File 'lib/helper/file_reader.rb', line 11 def readfile(path, opt={}) if File.readable?(path) bin = File.read(path).utf8! [bin, bin.former_enc ||'ascii-8bit' ] else raise ArgumentError.new("File is not readable!") end end |