gpt4 book ai didi

arrays - ruby 中有像 object.in(array) 这样的东西吗?

转载 作者:数据小太阳 更新时间:2023-10-29 07:25:25 25 4
gpt4 key购买 nike

<分区>

所以标准的写法似乎是array.include?(object)。然而,我发现与 object.in(array) 相比,它更难快速阅读和理解。 ruby 中有这样的东西吗?

刚才打的这个例子是(user_role是一个字符串,allowed_user_roles是一个字符串数组):

allowed_user_roles.include?(user_role)

我知道这可能是个人偏好,但我发现它更容易阅读和理解。

user_role.in(allowed_user_roles)

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com