Class: File

Inherits:
Object show all
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

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

Returns:

  • (Boolean)


7
8
9
# File 'lib/sane/bugs.rb', line 7

def executable? *args
  File.stat(*args).executable? rescue nil
end

.homeObject



2
3
4
# File 'lib/sane/file_home.rb', line 2

def self.home
  File.expand_path('~') # TODO use more ENV variables [?]
end

.original_basenameObject



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