• 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

言わずもがな、

「lower-camel caseな文字列(以下、LCC)」は "xxxYyyZzz"

な感じで、

「アンダースコア区切りな文字列(以下、underscore)」は、 "xxx_yyy_zzz"

な感じです。

では、早速変換。

LCC → underscore

   1  "helloWorld".gsub(/([A-Z])/){'_' + $1.downcase}
   2  #=> "hello_world"

underscore → LCC

   1  "hello_world".gsub(/_([a-z])/){$1.upcase}
   2  #=> "helloWorld"

以上!

posted by Png y_tsuda on Tue 23 Jun 2009 at 11:29
Contents
lower-camel caseな文字列とアンダースコア区切りな文字列の相互変換をRubyで
Comments
Aleksey: The uname check is only due to a somewhat slopp... '11-2
Yu Tsuda: あぁ、そうですね、、syncすると戻ってしまいますね・・・。 ご指摘ありがとうございます!! '09-7
ursm: /usr/portage 以下のファイルは更新のたび元に戻ってしまうので、/etc/porta... '09-7
Yu Tsuda: 見た目だけでも、わざわざGentooをこういうリストに入れてるのがすごいなぁと思ったりしたので... '09-3
Leonard Chin (レオ): ただし、VirtualBoxで「Gentoo」などを選択しても、別にどのOSを入れても大丈夫だ... '09-3
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ