aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/string/conversions.rb
diff options
context:
space:
mode:
authorMikel Lindsaar <raasdnil@gmail.com>2010-04-25 17:07:55 +1000
committerMikel Lindsaar <raasdnil@gmail.com>2010-04-25 17:07:55 +1000
commite1b255aca456a5b456111b09237805fd32d15111 (patch)
treea87c8b8989449a9dbdf1c6897901f6957ec021dc /activesupport/lib/active_support/core_ext/string/conversions.rb
parent60ab54113fa833a1258d687673561b9474964149 (diff)
parenta5955196f2ed8a69c49a1a8c0c617ab91cb8d716 (diff)
downloadrails-e1b255aca456a5b456111b09237805fd32d15111.tar.gz
rails-e1b255aca456a5b456111b09237805fd32d15111.tar.bz2
rails-e1b255aca456a5b456111b09237805fd32d15111.zip
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'activesupport/lib/active_support/core_ext/string/conversions.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/string/conversions.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb
index 52946f9037..4cc36147f8 100644
--- a/activesupport/lib/active_support/core_ext/string/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/string/conversions.rb
@@ -3,7 +3,27 @@ require 'active_support/core_ext/time/publicize_conversion_methods'
require 'active_support/core_ext/time/calculations'
class String
- # 'a'.ord == 'a'[0] for Ruby 1.9 forward compatibility.
+ # Returns the codepoint of the first character of the string, assuming a
+ # single-byte character encoding:
+ #
+ # "a".ord # => 97
+ # "à".ord # => 224, in ISO-8859-1
+ #
+ # This method is defined in Ruby 1.8 for Ruby 1.9 forward compatibility on
+ # these character encodings.
+ #
+ # <tt>ActiveSupport::Multibyte::Chars#ord</tt> is forward compatible with
+ # Ruby 1.9 on UTF8 strings:
+ #
+ # "a".mb_chars.ord # => 97
+ # "à".mb_chars.ord # => 224, in UTF8
+ #
+ # Note that the 224 is different in both examples. In ISO-8859-1 "à" is
+ # represented as a single byte, 224. In UTF8 it is represented with two
+ # bytes, namely 195 and 160, but its Unicode codepoint is 224. If we
+ # call +ord+ on the UTF8 string "à" the return value will be 195. That is
+ # not an error, because UTF8 is unsupported, the call itself would be
+ # bogus.
def ord
self[0]
end unless method_defined?(:ord)