Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4612

Convert camelCase to dash-case (hypens) in pure ruby

$
0
0

There are plenty of posts about the opposite way.

But how to I convert camelCase to camel-case in ruby? My regex-game is pretty low ... here is it the other way around:

def underscore(string)  string.gsub(/::/, '/').  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').  gsub(/([a-z\d])([A-Z])/,'\1_\2').  tr("-", "_").  downcaseend

Viewing all articles
Browse latest Browse all 4612

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>