言わずもがな、
「lower-camel caseな文字列(以下、LCC)」は** "xxxYyyZzz" **
な感じで、
「アンダースコア区切りな文字列(以下、underscore)」は、** "xxx_yyy_zzz" **
な感じです。
では、早速変換。
LCC → underscore
ruby>>
"helloWorld".gsub(/([A-Z])/){'_' + $1.downcase}
#=> "hello_world"
<<--
underscore → LCC
ruby>>
"hello_world".gsub(/_([a-z])/){$1.upcase}
#=> "helloWorld"
<<--
以上!
posted by
y_tsuda on Tue 23 Jun 2009 at 11:33 with 0 comments