如何检查哈希中是否存在特定密钥? [英] How to check if a specific key is present in a hash or not?

查看:69
本文介绍了如何检查哈希中是否存在特定密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要检查会话哈希中是否存在用户"键.我该怎么办?

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.

推荐答案

Hashkey?方法告诉您是否存在给定密钥.

Hash's key? method tells you whether a given key is present or not.

session.key?("user")

这篇关于如何检查哈希中是否存在特定密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆