エントリーの編集
エントリーの編集は全ユーザーに共通の機能です。
必ずガイドラインを一読の上ご利用ください。
Feature #11999: MatchData#to_h to get a Hash from named captures - Ruby master - Ruby Issue Tracking System
記事へのコメント1件
- 注目コメント
- 新着コメント
注目コメント算出アルゴリズムの一部にLINEヤフー株式会社の「建設的コメント順位付けモデルAPI」を使用しています
- バナー広告なし
- ミュート機能あり
- ダークモード搭載
関連記事
Feature #11999: MatchData#to_h to get a Hash from named captures - Ruby master - Ruby Issue Tracking System
class MatchData def to_h self.names.map { |n| [n, self[n]] }.to_h end end p '12'.match(/(?<a>.)(?... class MatchData def to_h self.names.map { |n| [n, self[n]] }.to_h end end p '12'.match(/(?<a>.)(?<b>.)(?<c>.)?/).to_h #=> {"a"=>"1", "b"=>"2", "c"=>nil} Sometimes I want to get a Hash from named capture, but currently I have to use #names + #captures. How about adding MatchData#to_h for convenience way?
2016/03/05 リンク