Created
July 11, 2012 15:06
-
-
Save tiegz/3091010 to your computer and use it in GitHub Desktop.
force_encoding monkeypatch for Ruby 1.8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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