From: her@... Date: 2016-01-18T06:37:24+00:00 Subject: [ruby-core:72897] [Ruby trunk - Feature #11999] [Open] MatchData#to_h to get a Hash from named captures Issue #11999 has been reported by Shota Fukumori. ---------------------------------------- Feature #11999: MatchData#to_h to get a Hash from named captures https://bugs.ruby-lang.org/issues/11999 * Author: Shota Fukumori * Status: Open * Priority: Normal * Assignee: ---------------------------------------- ~~~ class MatchData def to_h self.names.map { |n| [n, self[n]] }.to_h end end p '12'.match(/(?.)(?.)(?.)?/).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? -- https://bugs.ruby-lang.org/ Unsubscribe: