Convert named matches in MatchData to Hash
问题 I have a rather simple regexp, but I wanted to use named regular expressions to make it cleaner and then iterate over results. Testing string: testing_string = "111x222b333" My regexp: regexp = %r{ (?<width> [0-9]{3} ) {0} (?<height> [0-9]{3} ) {0} (?<depth> [0-9]+ ) {0} \g<width>x\g<height>b\g<depth> }x dimensions = regexp.match(testing_string) This work like a charm, but heres where the problem comes: dimensions.each { |k, v| dimensions[k] = my_operation(v) } # ERROR ! undefined method