Ruby regex key search

前端 未结 4 1917
情书的邮戳
情书的邮戳 2021-02-04 13:28

http://ruby-doc.org/core-1.9.3/Hash.html#method-i-include-3F

It is possible to convert hash.has_key?(String) to have a regex search capabilities?

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-04 13:45

    I think that using any? is a good solution as stated by qqbenq, but I would prefer using it with grep since it's more succinct.

    hash.keys.grep(/regexp/).any?
    

提交回复
热议问题