Convert named matches in MatchData to Hash

后端 未结 5 1406
抹茶落季
抹茶落季 2021-02-12 13:45

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_s         


        
5条回答
  •  情深已故
    2021-02-12 13:51

    If you want to keep the names, you can do

    new_dimensions = {}
    dimensions.names.each { |k| new_dimensions[k] = my_operation(dimensions[k]) }
    

提交回复
热议问题