views:

18

answers:

2

hi

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

+2  A: 

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">
Swanand
If this isn't what you are looking for, then I am afraid you will have to be a bit more lucid with the question.
Swanand
i am looking for the same, thank u very much
nirmal
+1  A: 
irb(main):005:0> arr = ["#"]
irb(main):006:0> elem = arr.first
irb(main):008:0> elem == "#"
=> true
bnaul
i am looking for the same, thank u very much
nirmal