I have this small script which I wrote to rename variables in my JS file.
  puts "Current name?"
  current_name = gets.chomp
  puts "New name? (Recommended usage of $ prefix)"
  new_name = gets.chomp
  #
  File.open(file_name, 'r+') do |file|
    file_content = file.read
    edited_file = file_content.sub "var "+current_name+" = ", "var "+new_name+" = "
    edited_file = edited_file.gsub current_name+".", new_name+"." 
    file.truncate(0)
    file.write(edited_file)
  end
When I run it, it changes all variable names and that looks just fine in my Atom text editor. But if I open this same file in Sublime text editor all characters are bunch of numbers.
Look at the screenshot (Sublime editor in front and Atom in background)
After trying this: Write and read a file with utf-8 encoding
  File.open(file_name, 'r+:UTF-8') do |file|
    file_content = file.read
    edited_file = file_content.sub "var "+current_name+" = ", "var "+new_name+" = "
    edited_file = edited_file.gsub current_name+".", new_name+"."
    file.truncate(0)
    file.write edited_file
  end
The invalid characters still appear and valid output afterwards. Here is screenshot:

