public
Description: A library that wraps Glib2 Unicode manipulation methods to speed up ActiveSupport::Multibyte
Homepage:
Clone URL: git://github.com/Manfred/unichars.git
unichars / README
100644 65 lines (37 sloc) 1.388 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
-%{ Unichars }%-
 
Unichars is a simple wrapper around Glib2. It was originally written to speed up ActiveSupport::Multibyte on Ruby 1.8 but it can probably used for other things as well.
 
 
--^^--^^- INSTALLING -^^--^^--
 
INSTALLING ON MAC OS X
 
$ port install glib2
$ gem install unichars
 
INSTALLING ON DEBIAN
 
$ apt-get install libglib2.0-dev
$ gem install unichars
 
 
--^^--^^- EXAMPLES -^^--^^--
 
FOR USE WITH RAILS
 
In config/environment.rb add:
 
  config.gem 'unichars'
 
Add config/initializers/unichars.rb:
 
  ActiveSupport::Multibyte.proxy_class = Unichars
 
After that you can just use Unichars through the character proxy on String:
 
  '¡Ay Dios mío!'.chars.reverse
 
FOR USE WITH ACTIVESUPPORT WITHOUT RAILS
 
Note that you probably want to load ActiveSupport before loading Unichars because Unichars subclasses itself from ActiveSupport::Multibyte::Chars when you do so.
 
  require 'rubygems' rescue LoadError
  require 'activesupport'
  require 'unichars'
  ActiveSupport::Multibyte.proxy_class = Unichars
 
After that you can just use Unichars through the character proxy on String:
 
  '¡Ay Dios mío!'.chars.reverse
 
FOR USE WITHOUT ACTIVESUPPORT
 
Yeah, so, ehm. Yeah.
 
  require 'rubygems' rescue LoadError
  require 'unichars'
 
After that you can do:
 
  Unichars.new('¡Ay Dios mío!').reverse
 
Or maybe:
 
  class String
    def chars
      Unichars.new(self)
    end
  end