gpt4 book ai didi

ruby-on-rails - ruby rails : short hand to put commas in between elements in an array?

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

users_allowed_to_be_viewed.map {|u| "#{u.id},"}

但这给出了 1,2,3,

什么是获得类似 1,2,3

的捷径

最佳答案

数组?

来自 http://ruby-doc.org/core/classes/Array.html

 array.join(sep=$,) → str

Returns a string created by converting each element of the array to a string, separated by sep.

[ "a", "b", "c" ].join #=> "abc"
[ "a", "b", "c" ].join("-") #=> "a-b-c"

关于ruby-on-rails - ruby rails : short hand to put commas in between elements in an array?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3424082/

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