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
精彩评论