在 ruby 中使用另一个值数组搜索一个数组
所以我有一个数组,显示允许哪些级别执行操作。
allowed = ["user", "admin"]
还有另一个数组显示用户属于哪些组。
groups = ["user", "crazy"]
在允许的数组中搜索用户所属的任何组的最佳方法是什么?我知道这很容易,但我在这里画了一个真正的空白......
So I have an array which shows which levels are allowed to do things.
allowed = ["user", "admin"]
There's another array that shows which groups a user belongs to.
groups = ["user", "crazy"]
What's the best way to search the allowed array for ANY of the groups a user belongs to? I know it's easy but I'm drawing a real blank here...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需
&
:Just
&
:转换为集合并进行交集。
Convert to a set and do an intersection.