Class: Text

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

Class Method Summary collapse

Class Method Details

.replace_in_file(filename, search, replace) ⇒ Object



923
924
925
926
927
928
929
930
931
# File 'lib/dev_commands.rb', line 923

def self.replace_in_file(filename,search,replace)
  text1 = IO.read(filename)
  text2 = text1.gsub(search) { |str| str=replace }
  unless text1==text2
    File.open(filename,"w") { |f| f.puts text2 }
    return true
  end
  false
end

.replace_in_glob(glob, search, replace) ⇒ Object



919
920
921
# File 'lib/dev_commands.rb', line 919

def self.replace_in_glob(glob,search,replace)
  Dir.glob(glob).each{ |f| replace_in_file(f,search,replace) }
end