From: her@... Date: 2016-01-18T16:53:33+00:00 Subject: [ruby-core:72905] [Ruby trunk - Feature #11999] MatchData#to_h to get a Hash from named captures Issue #11999 has been updated by Shota Fukumori. > is not always able to convert to Hash/Map. Ah -- agreed. How about MatchData#named_captures? I can't think this name is the best, suggestions welcome. ---------------------------------------- Feature #11999: MatchData#to_h to get a Hash from named captures https://bugs.ruby-lang.org/issues/11999#change-56134 * 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? ---Files-------------------------------- 11999.diff (2.77 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: