Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Underscoming a class

Reply
Thread Tools

Underscoming a class

 
 
Allen Walker
Guest
Posts: n/a
 
      09-30-2008
If I have a String like "DistributionMethod" is there any helper out
there that will turn it into "distribution_method" ?
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Todd Benson
Guest
Posts: n/a
 
      09-30-2008
On Mon, Sep 29, 2008 at 10:22 PM, Allen Walker <> wrote:
> If I have a String like "DistributionMethod" is there any helper out
> there that will turn it into "distribution_method" ?


I'm sure there's one out there, but for simple cases...

s = "SomeCamelCase"
s.scan(/.*?[A-Z].*?[^A-Z]*?/).map {|w| w.downcase}.join("_")

Todd

 
Reply With Quote
 
 
 
 
Trans
Guest
Posts: n/a
 
      09-30-2008


On Sep 29, 11:22=A0pm, Allen Walker <ausw...@gmail.com> wrote:
> If I have a String like "DistributionMethod" =A0is there any helper out
> there that will turn it into "distribution_method" ?


Check out the English library (require 'english/style').

http://english.rubyforge.org

Also, Facets and ActiveSupport have such methods.

The method names to look for are #snakecase, #underscore, and
#methodize.

T.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
Generic class literals - e.g,, Class<Map<String, Integer>>.class Purush Java 4 04-13-2005 08:40 PM
instanciate a class in a jar file with class.forname, while my main class is in another jar cyril Java 2 08-25-2004 06:55 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57