Skip to content

Instantly share code, notes, and snippets.

@tiegz
Created July 11, 2012 15:06
Show Gist options
  • Save tiegz/3091010 to your computer and use it in GitHub Desktop.
Save tiegz/3091010 to your computer and use it in GitHub Desktop.
force_encoding monkeypatch for Ruby 1.8
if RUBY_VERSION =~ /1\.8/
class String
def force_encoding(encoding)
self
end
end
end
# 1.8.7 :025 > Benchmark.ms { 10000.times { x = "" } }
# => 2.4268627166748
# 1.8.7 :026 > Benchmark.ms { 10000.times { x = "".force_encoding("utf-8") } }
# => 10.983943939209
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment