Skip to content

Instantly share code, notes, and snippets.

@sb8244
Created March 13, 2015 20:54
Show Gist options
  • Save sb8244/a44cfa7463c65e89612e to your computer and use it in GitHub Desktop.
Save sb8244/a44cfa7463c65e89612e to your computer and use it in GitHub Desktop.
Ernie, play nice with Rails!
# Rails will cause the encoding to slip to ASCII-8BIT for some reason.
# This works fine when all rails libraries aren't loaded onto the ernie process
class Ernie
def self.write_berp(output, ruby)
data = BERT.encode(ruby)
output.write([data.length].pack("N").force_encoding("utf-8"))
output.write(data.force_encoding("utf-8"))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment