# Newbie question (Array.\<\<)

**URL:** <https://www.ruby-forum.com/t/newbie-question-array/51841>\
**Category:** Ruby\
**Created:** [January 8, 2006, 4:17am UTC](https://www.ruby-forum.com/t/newbie-question-array/51841 "2006-01-08T04:17:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![toadkicker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5fc32e/32.png) [@toadkicker](https://www.ruby-forum.com/u/toadkicker)\
**Post date:** [January 8, 2006, 4:17am UTC](https://www.ruby-forum.com/t/newbie-question-array/51841/1 "2006-01-08T04:17:44Z")

</div>

I must be missing something…

I’ve got the following class method. The problem is the line that reads  
objs  
\<\< self.new(obj). The first time through the loop, the objs array looks  
correct. After the second iteration however, the objs array contains 2  
copies of the second object created.

Here is the output from the method:

“00630000003BqXwAAK”  
[00630000003BqXwAAK]  
“00630000003awD3AAI”  
[00630000003awD3AAI, 00630000003awD3AAI]

and here is the method:

```
def FindAll(criteria)
  self.GetAllFields if (defined? @@attribs) == nil
  result = @@connection.query([:query, "select #{@@attribs} from #{

```

self.to\_s} where #{criteria}"])  
objs = []  
result.queryResponse.result.records.each do |obj|  
p obj.Id  
objs \<\< self.new(obj)  
p objs  
end  
objs  
end

Thanks!

Todd B.

---

<div class="post-metadata">

**Author:** ![toadkicker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5fc32e/32.png) [@toadkicker](https://www.ruby-forum.com/u/toadkicker)\
**Post date:** [January 8, 2006, 5:53am UTC](https://www.ruby-forum.com/t/newbie-question-array/51841/2 "2006-01-08T05:53:55Z")

</div>

[Todd B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), 2006-01-08 04.15 CET]

> [00630000003BqXwAAK]  
> result.queryResponse.result.records.each do |obj|  
> Probably this object is being reused ----------------^^^

Look at the documentation (or source code) of the method that does the  
iteration.

Good luck.

---

<div class="post-metadata">

**Author:** ![toadkicker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5fc32e/32.png) [@toadkicker](https://www.ruby-forum.com/u/toadkicker)\
**Post date:** [January 8, 2006, 5:56am UTC](https://www.ruby-forum.com/t/newbie-question-array/51841/3 "2006-01-08T05:56:55Z")

</div>

[Todd B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), 2006-01-08 04.15 CET]

> [00630000003BqXwAAK]  
> result.queryResponse.result.records.each do |obj|  
> p obj.Id  
> objs \<\< self.new(obj)  
> Or, more probably ^^^^^^^^ here is the problem :). Try self.class.new if  
> you  
> want a new object of the same class as self.
