Ruby: Easiest Way to Filter Hash Keys?

前端 未结 13 1213

I have a hash that looks something like this:

params = { :irrelevant => \"A String\",
           :choice1 => \"Oh look, another one\",
           :choi         


        
13条回答
  •  天涯浪人
    2020-11-30 18:44

    With Hash::select:

    params = params.select { |key, value| /^choice\d+$/.match(key.to_s) }
    

提交回复
热议问题