How to change Hash values?

后端 未结 12 1930
悲&欢浪女
悲&欢浪女 2020-12-12 11:22

I\'d like to replace each value in a hash with value.some_method.

For example, for given a simple hash:

{\"a\" => \"b\",         


        
12条回答
  •  孤城傲影
    2020-12-12 12:05

    If you know that the values are strings, you can call the replace method on them while in the cycle: this way you will change the value.

    Altohugh this is limited to the case in which the values are strings and hence doesn't answer the question fully, I thought it can be useful to someone.

提交回复
热议问题