I noticed this while trying to include
active_support/core_ext/string/inflections and use camelize and
parameterize. The first worked fine, while the second threw an
error.
parameterize depends on transliterate, which is defined in
transliterate.rb:
def transliterate(string, replacement = "?")
I18n.transliterate(ActiveSupport::Multibyte::Unicode.normalize(
ActiveSupport::Multibyte::Unicode.tidy_bytes(string), :c),
:replacement => replacement)
end
That I18n exists without a require statement and hence trying to
require these files and use on their own fails with the obvious
error:
~ > ./foo.rb
/Users/jack/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/inflector/transliterate.rb:61:in
transliterate': uninitialized constant
ActiveSupport::Inflector::I18n (NameError)
from /Users/jack/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/inflector/transliterate.rb:83:in `parameterize'
If you add this to the top of the file:
require 'active_support/i18n'
then I18n will be defined, but will fail when it tries to load
its hooks:
~ > ./foo.rb
/Users/jack/.rvm/gems/ruby-1.9.2-p0/gems/activesupport-3.0.0/lib/active_support/i18n.rb:9:in
<top (required)>': undefined
methodrun_load_hooks' for ActiveSupport:Module
(NoMethodError)
from <internal:lib/rubygems/custom_require>:29:in `require'
If we add a require for hooks into I18n like so:
require 'active_support/lazy_load_hooks'
then the script works as we'd expect:
!/usr/bin/env ruby
require 'active_support/inflector/transliterate'
include ActiveSupport::Inflector
p parameterize("foo bar")
~ > ./foo.rb "foo-bar"
So in summary,
- active_support/i18n.rb should require lazy_load_hooks if it's
going to try and use them
- active_support/inflector/transliterate.rb should require
active_support/i18n.rb if it wants to use it
I'm not sure how we should write a test for this. The
inflector_test.rb in active_support does this:
require 'active_support'
which should probably be fixed as well. Thoughts?