From 4e60eebae05aeec65e4894e3901c9d61c9b32910 Mon Sep 17 00:00:00 2001 From: Jason Cheow Date: Wed, 26 Nov 2008 22:16:28 +0800 Subject: Add ActiveSupport::Multibyte::Chars#ord method so that it returns correct Unicode value instead of falling back on String#ord in CoreExtensions, which is not multibyte compatible [#1483 state:committed] Signed-off-by: Jeremy Kemper --- activesupport/lib/active_support/multibyte/chars.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index be9c6d3567..a00b165222 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -344,6 +344,14 @@ module ActiveSupport #:nodoc: end alias_method :[], :slice + # Converts first character in the string to Unicode value + # + # Example: + # 'こんにちは'.mb_chars.ord #=> 12371 + def ord + self.class.u_unpack(@wrapped_string)[0] + end + # Convert characters in the string to uppercase. # # Example: -- cgit v1.2.3