我在数组中有一个元素,
[#<Name id: 23, first_name: "anderson", last_name: "gorge">]
如何删除数组块,以便我想要它
#<Name id: 23, first_name: "anderson", last_name: "gorge">
没有数组块
答案 0 :(得分:2)
你的意思是你在一个数组中有一个单个元素,你想要提取它吗?有很多方法可以做到这一点,2很快就会浮现在脑海中:
>> 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">
答案 1 :(得分:1)
irb(main):005:0> arr = ["#"]
irb(main):006:0> elem = arr.first
irb(main):008:0> elem == "#"
=> true