Enumerable#grepを使う事で、文字列の配列から、 所望のパターンにマッチするものだけを抜き出す事が出来ますが、 以下のようにブロックを指定する事で、 マッチした部分だけを取り出す事が出来ます。

   1  Dir["config/environments/*.rb"].grep(%r{(\w+)\.rb$}){$1}
   2  #=> ["development", "production", "rake", "staging", "test"]

痒いところに手が届く感じですね。

posted by Png genki on Thu 30 Apr 2009 at 14:32
Contents
文字列の配列から正規表現にマッチする部分を抜き出す
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
KingofSmack: Here also good reads for this mobile applicatio... '14-5
Spencer: You don't have to re-compile it, this version w... '14-4
staiano: Any chance we can get a recompile for 10.9? '14-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ