From: Rick DeNatale Date: 2010-07-06T00:10:01+09:00 Subject: Re: name correspondence On Mon, Jul 5, 2010 at 6:25 AM, Brian Candler wrote: > Thomas Sawyer wrote: >>     Library: foo-bar >>     Directory: lib/foo/bar >>     Namespace: Foo::Bar >> >>     Library: foo_bar >>     Directory: lib/foo_bar >>     Namespace: FooBar >> >> That being the case I think Ruby needs to include methods to make it >> easy to translate between these. In ActiveSupport these methods are >> String#pathize and String#methodize. I would think there would also be >> something like String#modulize. > > Perhaps you're thinking of camelize and underscore in > lib/active_support/inflector.rb > >    # Examples: >    #   "active_record".camelize                # => "ActiveRecord" >    #   "active_record".camelize(:lower)        # => "activeRecord" >    #   "active_record/errors".camelize         # => > "ActiveRecord::Errors" >    #   "active_record/errors".camelize(:lower) # => > "activeRecord::Errors" > >    # Examples: >    #   "ActiveRecord".underscore         # => "active_record" >    #   "ActiveRecord::Errors".underscore # => active_record/errors > > Each of these methods is only a few lines. I've seen them copy-pasted in > several projects... There's also constantize ruby-1.8.7-p173 > "ActiveRecord".constantize => ActiveRecord ruby-1.8.7-p173 > "active_record".camelize.constantize => ActiveRecord ruby-1.8.7-p173 > "ActiveRecord::Errors".constantize => ActiveRecord::Errors Also a few lines of code, although there are two versions one for Ruby 1.9.2 because of changes to Module#const_get -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale