Skip to content

Instantly share code, notes, and snippets.

@osheroff
Created June 27, 2012 18:35
Show Gist options
  • Save osheroff/3005917 to your computer and use it in GitHub Desktop.
Save osheroff/3005917 to your computer and use it in GitHub Desktop.
marshal utf-8 enforcement
module Marshal
class << self
def load_with_utf8_enforcement(object, other_proc=nil)
@utf8_proc ||= Proc.new do |o|
o.force_encoding("UTF-8") if o.is_a?(String)
other_proc.call(o) if other_proc
o
end
load_without_utf8_enforcement(object, @utf8_proc)
end
alias_method_chain :load, :utf8_enforcement
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment