From 7f25e2378358fbb09011ad932a6709831a7e59d2 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 18 Apr 2010 00:05:09 +0200 Subject: revises the rdoc of String#ord --- activesupport/lib/active_support/core_ext/string/conversions.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext/string/conversions.rb') diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index 52946f9037..d70f5d7241 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -3,7 +3,11 @@ 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 ASCII code of the first character of the string, assuming it belongs to ASCII. + # + # This method is defined for Ruby 1.9 forward compatibility on ASCII characters. + # + # See also ActiveSupport::Multibyte::Chars#ord. def ord self[0] end unless method_defined?(:ord) -- cgit v1.2.3 From 6f6cddb599f596cbfd414d880bb4c64d3f1d8ffb Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 18 Apr 2010 11:55:07 +0200 Subject: much complete rdoc for String#ord --- .../active_support/core_ext/string/conversions.rb | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/string/conversions.rb') diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index d70f5d7241..4cc36147f8 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -3,11 +3,27 @@ require 'active_support/core_ext/time/publicize_conversion_methods' require 'active_support/core_ext/time/calculations' class String - # Returns the ASCII code of the first character of the string, assuming it belongs to ASCII. + # Returns the codepoint of the first character of the string, assuming a + # single-byte character encoding: # - # This method is defined for Ruby 1.9 forward compatibility on ASCII characters. + # "a".ord # => 97 + # "à".ord # => 224, in ISO-8859-1 # - # See also ActiveSupport::Multibyte::Chars#ord. + # This method is defined in Ruby 1.8 for Ruby 1.9 forward compatibility on + # these character encodings. + # + # ActiveSupport::Multibyte::Chars#ord 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) -- cgit v1.2.3