开发者

RoR free element from array

开发者 https://www.devze.com 2023-01-19 04:54 出处:网络
i have an element in a array such that, [#<Name id: 23, first_name: \"anderson\", last_name: \"gorge\">]

i have an element in a array such that,

[#<Name id: 23, first_name: "anderson", last_name: "gorge">]

how can i remove the array block, so that i want it as

#<Name id: 23, first_name: "anderson", last_name: "gorge">
开发者_如何学运维

without array block


Do you mean you have a single element in an array and you want to extract it? There so many ways of doing it, 2 that quickly come to mind are:

>> obj = [#<Name id: 23, first_name: "anderson", last_name: "gorge">].first
=> #<Name id: 23, first_name: "anderson", last_name: "gorge">
>> obj = [#<Name id: 23, first_name: "anderson", last_name: "gorge">].shift
=> #<Name id: 23, first_name: "anderson", last_name: "gorge">


irb(main):005:0> arr = ["#"]
irb(main):006:0> elem = arr.first
irb(main):008:0> elem == "#"
=> true
0

精彩评论

暂无评论...
验证码 换一张
取 消