# Name correspondence

**URL:** <https://www.ruby-forum.com/t/name-correspondence/191058>\
**Category:** Ruby\
**Created:** [July 3, 2010, 8:44pm UTC](https://www.ruby-forum.com/t/name-correspondence/191058 "2010-07-03T20:44:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [July 3, 2010, 8:44pm UTC](https://www.ruby-forum.com/t/name-correspondence/191058/1 "2010-07-03T20:44:02Z")

</div>

The proposed Ruby Package Standard states:

File names and directory structure SHOULD correspond like this:

```
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.

Without such methods I think it is a bit much to ask of developers to  
keep this correspondence. I have code that needs to do such  
translations dynamically and because Ruby does not have such methods,  
I used a FooBar -\> foobar.rb correspondence instead (easily  
transformed via #downcase). A fact that has led me to generally use  
this correspondence throughout all my projects.

I’m all for the proposed standard, but Ruby needs to support it too.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [July 5, 2010, 12:25pm UTC](https://www.ruby-forum.com/t/name-correspondence/191058/2 "2010-07-05T12:25:05Z")

</div>

Thomas S. 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…

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [July 5, 2010, 5:10pm UTC](https://www.ruby-forum.com/t/name-correspondence/191058/3 "2010-07-05T17:10:36Z")

</div>

On Mon, Jul 5, 2010 at 6:25 AM, Brian C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > easy to translate between these. In ActiveSupport these methods are  
> > “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/](http://talklikeaduck.denhaven2.com/)  
Github: [rubyredrick (Rick DeNatale) · GitHub](http://github.com/rubyredrick)  
Twitter: @RickDeNatale  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [July 5, 2010, 7:09pm UTC](https://www.ruby-forum.com/t/name-correspondence/191058/4 "2010-07-05T19:09:27Z")

</div>

On Jul 5, 6:25 am, Brian C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 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

Oh? My bad, I thought it had #pathize and #methodize too.

> ```
> # "ActiveRecord::Errors".underscore # => active_record/errors
> 
> ```
> 
> Each of these methods is only a few lines. I’ve seen them copy-pasted in  
> several projects…

In Facets those are #camelcase and #snakecase, but it also has the  
other methods – No problem getting access to such methods. Just think  
Ruby needs to support something along these lines out the box if the  
correspondence should be considered a standard.
