Class: File
- Defined in:
- lib/sane/sane_random.rb,
lib/sane/bugs.rb,
lib/sane/bugs.rb,
lib/sane/file.rb,
lib/sane/file_home.rb,
lib/sane/file_filename.rb
Overview
abstracted from require ‘facets/file’ ===>
Class Method Summary collapse
- .basename(*args) ⇒ Object (also: filename)
- .binread(filename) ⇒ Object
- .binwrite(path, data) ⇒ Object
- .executable?(*args) ⇒ Boolean
- .home ⇒ Object
- .original_basename ⇒ Object
-
.write(path, data) ⇒ Object
Writes the given data to the given path and closes the file.
Class Method Details
.basename(*args) ⇒ Object Also known as: filename
20 21 22 |
# File 'lib/sane/bugs.rb', line 20 def File.basename *args original_basename(*args).dup end |
.binread(filename) ⇒ Object
2 3 4 |
# File 'lib/sane/file.rb', line 2 def self.binread filename File.open(filename, 'rb')do |f| f.read; end end |
.binwrite(path, data) ⇒ Object
22 23 24 25 26 |
# File 'lib/sane/sane_random.rb', line 22 def self.binwrite(path, data) File.open(path, "wb") do |file| return file.write(data) end end |
.executable?(*args) ⇒ Boolean
7 8 9 |
# File 'lib/sane/bugs.rb', line 7 def executable? *args File.stat(*args).executable? rescue nil end |
.home ⇒ Object
2 3 4 |
# File 'lib/sane/file_home.rb', line 2 def self.home File.('~') # TODO use more ENV variables [?] end |
.original_basename ⇒ Object
19 |
# File 'lib/sane/bugs.rb', line 19 alias :original_basename :basename |
.write(path, data) ⇒ Object
Writes the given data to the given path and closes the file. This is done in binary mode, complementing IO.read
in standard Ruby.
Returns the number of bytes written.
CREDIT: facets/Gavin Sinclair
16 17 18 19 20 |
# File 'lib/sane/sane_random.rb', line 16 def self.write(path, data) File.open(path, "w") do |file| return file.write(data) end end |