如何检查哈希中是否存在特定密钥? [英] How to check if a specific key is present in a hash or not?
本文介绍了如何检查哈希中是否存在特定密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要检查会话哈希中是否存在用户"键.我该怎么办?
I want to check whether the "user" key is present or not in the session hash. How can I do this?
请注意,我不想检查键的值是否为nil.我只想检查用户" 键是否存在.
Note that I don't want to check whether the key's value is nil or not. I just want to check whether the "user" key is present.
推荐答案
Hash
的key?
方法告诉您是否存在给定密钥.
Hash
's key?
method tells you whether a given key is present or not.
session.key?("user")
这篇关于如何检查哈希中是否存在特定密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文