This project is archived and is in readonly mode.

#5630 ✓stale
jack dempsey (jackdempsey)

active_support/inflector/transliterate using I18n without requiring it

Reported by jack dempsey (jackdempsey) | September 13th, 2010 @ 11:32 PM

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,

  1. active_support/i18n.rb should require lazy_load_hooks if it's going to try and use them
  2. 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?

Comments and changes to this ticket

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:31 PM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:31 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages