aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames McKinney <james@slashpoundbang.com>2011-10-17 01:13:28 -0400
committerJames McKinney <james@slashpoundbang.com>2011-10-17 01:13:28 -0400
commit07a59079c775675e27f96d68064a8f80c3c431ab (patch)
treedd90ceed525175082f013ef112beccab23b2b25b
parentcc83344b7c05f675777e37d462874ecfb7083c94 (diff)
add String#is_binary_data? in Ruby 1.9
-rw-r--r--config/environment.rb1
-rw-r--r--lib/ruby19.rb8
2 files changed, 9 insertions, 0 deletions
diff --git a/config/environment.rb b/config/environment.rb
index 91839c043..7c0662d3a 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -134,6 +134,7 @@ I18n.available_locales = available_locales.map {|locale_name| locale_name.to_sym
I18n.default_locale = default_locale
# Load monkey patches and other things from lib/
+require 'ruby19.rb'
require 'tmail_extensions.rb'
require 'activesupport_cache_extensions.rb'
require 'timezone_fixes.rb'
diff --git a/lib/ruby19.rb b/lib/ruby19.rb
new file mode 100644
index 000000000..39f48d74e
--- /dev/null
+++ b/lib/ruby19.rb
@@ -0,0 +1,8 @@
+if RUBY_VERSION.to_f == 1.9
+ class String
+ # @see syck/lib/syck/rubytypes.rb
+ def is_binary_data?
+ self.count("\x00-\x7F", "^ -~\t\r\n").fdiv(self.size) > 0.3 || self.index("\x00") unless self.empty?
+ end
+ end
+end \ No newline at end of file