39 lines
475 B
Ruby
39 lines
475 B
Ruby
|
require 'pathname'
|
||
|
|
||
|
class Pathname
|
||
|
alias +@ to_s
|
||
|
|
||
|
def chdir &exe
|
||
|
Dir.chdir self.to_s, &exe
|
||
|
end
|
||
|
alias cd chdir
|
||
|
|
||
|
# copies content of src in self as destination
|
||
|
def copy src, **opts
|
||
|
FileUtils.copy_file src.to_s, self.to_s, **opts
|
||
|
end
|
||
|
|
||
|
def replace_i
|
||
|
open 'r+' do |f|
|
||
|
lines = yield f
|
||
|
f.truncate 0
|
||
|
f.pos = 0
|
||
|
f.puts lines
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
class Symbol
|
||
|
alias +@ to_s
|
||
|
def -@
|
||
|
:"-#{self}"
|
||
|
end
|
||
|
end
|
||
|
|
||
|
class File
|
||
|
def reset
|
||
|
f.truncate 0
|
||
|
f.pos = 0
|
||
|
end
|
||
|
end
|