This project is archived and is in readonly mode.

#1355 ✓stale
Nick Eskelinen

Inflector.underscore() is not consistent with camelize()

Reported by Nick Eskelinen | November 11th, 2008 @ 05:02 PM | in 3.x

From the documentation of ActiveSupport::Inflector

underscore()

The reverse of camelize. Makes an underscored, lowercase form from the expression in the string.

However, underscore doesn't handle consecutive caps characters correctly.


"ERDiagram".underscore  # "er_diagram"
"er_diagram".camelize   # "ErDiagram"
"ERDiagram".underscore.camelize == "ERDiagram"  # false

Comments and changes to this ticket

  • Pratik

    Pratik March 12th, 2009 @ 03:58 PM

    • State changed from “new” to “incomplete”

    Can we please have a patch with failing tests ? http://guides.rails.info/contrib... should be helpful.

    Thanks !

  • Nick Eskelinen

    Nick Eskelinen March 13th, 2009 @ 07:10 PM

    • Tag set to activeresource, bug, inflector

    Hmm, so I tried to write a failing test, but it appears this behavior is explicitly tested for (with incorrect behavior, IMO) in inflector_test_cases.rb:

    
      CamelToUnderscoreWithoutReverse = {
        "HTMLTidy"              => "html_tidy",
        "HTMLTidyGenerator"     => "html_tidy_generator",
        "FreeBSD"               => "free_bsd",
        "HTML"                  => "html",
      }
    

    So it looks like there are 2 options: 1) Fix documentation to not claim that camelize() and underscore() are inverse functions (and warn that string.underscore.camelize != string) 2) Fix underscore() to break on (all) caps boundaries and provide a facility for making exceptions (probably via the Inflector#inflections method)

    My personal feeling is that #1 is ignoring the fundamental problem with the current behavior of underscore() -- there is no way to go from an underscored transformation back to the original camelized form.

    Comments?

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • rails

    rails February 26th, 2011 @ 12:00 AM

    • State changed from “incomplete” to “open”
    • Importance changed from “” to “”

    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.

  • rails

    rails February 26th, 2011 @ 12:00 AM

    • 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