If I have a String like “DistributionMethod” is there any helper out
there that will turn it into “distribution_method” ?
On Mon, Sep 29, 2008 at 10:22 PM, Allen W. [email protected]
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
On Sep 29, 11:22 pm, Allen W. [email protected] wrote:
If I have a String like “DistributionMethod” is there any helper out
there that will turn it into “distribution_method” ?
Check out the English library (require ‘english/style’).
Also, Facets and ActiveSupport have such methods.
The method names to look for are #snakecase, #underscore, and
#methodize.
T.