# Is there a built-in way to convert from snake\_case to CamelCase?

**URL:** <https://www.ruby-forum.com/t/is-there-a-built-in-way-to-convert-from-snake-case-to-camelcase/161965>\
**Category:** IronRuby\
**Created:** [March 4, 2009, 10:41am UTC](https://www.ruby-forum.com/t/is-there-a-built-in-way-to-convert-from-snake-case-to-camelcase/161965 "2009-03-04T10:41:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 4, 2009, 10:41am UTC](https://www.ruby-forum.com/t/is-there-a-built-in-way-to-convert-from-snake-case-to-camelcase/161965/1 "2009-03-04T10:41:46Z")

</div>

Hi,

looking if I can use the internals better: is there a built-in  
IronRuby way to convert “flow\_layout\_panel” to “FlowLayoutPanel” ? As  
it’s used all over the place when calling methods, I thought that  
maybe I could use it as well.

I’m currently using this which works well:

module Classifier  
def classify(string)  
string.gsub(/(^|\_)(.)/) { $2.upcase } # simplified version of  
Rails inflector  
end  
end

If I can remove some code though, I’m happy. Is the code to achieve  
this accessible ?

– Thibaut

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 4, 2009, 11:14am UTC](https://www.ruby-forum.com/t/is-there-a-built-in-way-to-convert-from-snake-case-to-camelcase/161965/2 "2009-03-04T11:14:11Z")

</div>

Well you can require activesupport  
Or you can look at [Inflector.NET](http://Inflector.NET) from Andrew P… He ported that  
inflection stuff from activesupport to .NET

On Wed, Mar 4, 2009 at 10:36 AM, Thibaut BarrÃ¨re

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 4, 2009, 11:16am UTC](https://www.ruby-forum.com/t/is-there-a-built-in-way-to-convert-from-snake-case-to-camelcase/161965/3 "2009-03-04T11:16:33Z")

</div>

Hi Ivan,

> Well you can require activesupport  
> Or you can look at [Inflector.NET](http://Inflector.NET) from Andrew P… He ported that  
> inflection stuff from activesupport to .NET

The code I’m using is an extract from activesupport inflector. I  
didn’t want to carry the whole dependency for the moment.

thanks for the pointer ([Inflector.NET](http://Inflector.NET)), I’ll have a look!

– Thibaut

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 4, 2009, 12:20pm UTC](https://www.ruby-forum.com/t/is-there-a-built-in-way-to-convert-from-snake-case-to-camelcase/161965/4 "2009-03-04T12:20:10Z")

</div>

I’ve added the inflector stuff to IronRuby MVC too. The only thing I  
added  
to the library was to make it all extension methods.  
In IronNails I also pulled in the files from active support because I  
didn’t  
want to take the dependency atm.  
On Wed, Mar 4, 2009 at 11:15 AM, Thibaut BarrÃ¨re

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 5, 2009, 5:56pm UTC](https://www.ruby-forum.com/t/is-there-a-built-in-way-to-convert-from-snake-case-to-camelcase/161965/5 "2009-03-05T17:56:45Z")

</div>

IronRuby has RubyUtils.MangleName/TryUnmangleName in  
/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyUtils.cs.

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Ivan Porto  
Carrero  
Sent: Wednesday, March 04, 2009 2:57 AM  
To: removed\_email\_address@domain.invalid  
Subject: Re: [Ironruby-core] Is there a built-in way to convert from  
snake\_case to CamelCase ?

I’ve added the inflector stuff to IronRuby MVC too. The only thing I  
added to the library was to make it all extension methods.  
In IronNails I also pulled in the files from active support because I  
didn’t want to take the dependency atm.  
On Wed, Mar 4, 2009 at 11:15 AM, Thibaut BarrÃ¨re  
\<removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:  
Hi Ivan,

> Well you can require activesupport  
> Or you can look at [Inflector.NET](http://Inflector.NET) from Andrew P… He ported that  
> inflection stuff from activesupport to .NET  
> The code I’m using is an extract from activesupport inflector. I  
> didn’t want to carry the whole dependency for the moment.

thanks for the pointer ([Inflector.NET](http://Inflector.NET)), I’ll have a look!

– Thibaut

> > maybe I could use it as well.  
> > If I can remove some code though, I’m happy. Is the code to achieve  
> > Ironruby-core mailing list  
> > removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

* * *

Ironruby-core mailing list  
removed\_email\_address@domain.invalid[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [March 7, 2009, 9:59pm UTC](https://www.ruby-forum.com/t/is-there-a-built-in-way-to-convert-from-snake-case-to-camelcase/161965/6 "2009-03-07T21:59:10Z")

</div>

Hi Jimmy,

> IronRuby has RubyUtils.MangleName/TryUnmangleName in  
> /Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyUtils.cs.

thanks for the hint.

– Thibaut
