Ruby value of a hash key?

后端 未结 6 2157
暖寄归人
暖寄归人 2021-01-31 08:43

I\'ve got a list of values that are in a Ruby hash. Is there a way to check the value of the key and if it equals \"X\", then do \"Y\"?

I can test to see if the hash ha

6条回答
  •  悲&欢浪女
    2021-01-31 08:47

    How about this?

    puts "ok" if hash_variable["key"] == "X"
    

    You can access hash values with the [] operator

提交回复
热议问题