Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/file_instance_move.rb

Overview

This class adds some much needed (in my mind) copying and moving of files from a File instance.

Instance Method Summary collapse

Instance Method Details

#copy(destination) ⇒ Object

Copies the currently open file to destination, and returns a new File instance with the copied file



15
16
17
18
19
# File 'lib/file_instance_move.rb', line 15

def copy destination
  source = filename
  FileUtils.cp source, destination
  open destination
end

#cp(destination) ⇒ Object

Alias for #copy



32
33
34
# File 'lib/file_instance_move.rb', line 32

def cp destination
  copy destination
end

#filenameObject

Returns the filename of the currently open file



10
11
12
# File 'lib/file_instance_move.rb', line 10

def filename
  inspect[7..-2]
end

#move(destination) ⇒ Object

Moves the currently open file, and returns a new File instance with the moved file

  • You do not need to call close when using this method



23
24
25
26
27
28
29
# File 'lib/file_instance_move.rb', line 23

def move destination
  source = filename
  FileUtils.cp source, destination
  close
  FileUtils.rm source
  open destination
end

#mv(destination) ⇒ Object

Alias for #move



37
38
39
# File 'lib/file_instance_move.rb', line 37

def mv destination
  move destination
end