From: DJ Jazzy Linefeed Date: 2008-05-17T06:10:05+09:00 Subject: ruby 1.9 hates you and me and the encodings we rode in on so just get used to it. def prep_file(path) ret = '' x = File.open(path) x.lines.each do |l| l.gsub!('\n', ' ') ret << l end puts ret end ... compare.rb:64:in `gsub': broken UTF-8 string (ArgumentError) from compare.rb:64:in `block in prep_file' from compare.rb:63:in `each_line' from compare.rb:63:in `call' from compare.rb:63:in `each' from compare.rb:63:in `prep_file' from compare.rb:144:in `
' Hm. Okay, I love you ruby, we can just talk this thing out and I can get back to... x.lines.each do |l| ret << l end # (I love you too) Alright baby, Daddy gets confused and angry sometimes... do you wanna make a little string love...? ret = '' x = File.open(path) x.lines.each do |l| ret << l end puts ret.class # String Mhm, it smells like you do. Why don't we take this off... x.lines.each do |l| ret << l end puts ret.gsub!('a', 'test') end ... compare.rb:69:in `gsub!': broken UTF-8 string (ArgumentError) from compare.rb:69:in `prep_file' from compare.rb:145:in `
' Hey, Ruby, if it's that week of the month we can just cuddle. Here, try this... x.lines.each do |l| ret << l end puts ret ... # (big string) See, thats good. Thats a string and that's something we have in common, maybe we were just talking about different encodings. Let's see what it's made of. puts ret.encoding # UTF-8 I'm gonna go get a gallon of milk and I'll be back soon. You wait right there. (grumbles)