[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Underscoming a class

Allen Walker

9/30/2008 3:23:00 AM

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

2 Answers

Todd Benson

9/30/2008 4:14:00 AM

0

On Mon, Sep 29, 2008 at 10:22 PM, Allen Walker <auswalk@gmail.com> 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

Trans

9/30/2008 4:22:00 AM

0



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

Also, Facets and ActiveSupport have such methods.

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

T.