# \<\< == push?

**URL:** <https://www.ruby-forum.com/t/push/77566>\
**Category:** Ruby\
**Created:** [November 28, 2006, 9:18pm UTC](https://www.ruby-forum.com/t/push/77566 "2006-11-28T21:18:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [November 28, 2006, 9:18pm UTC](https://www.ruby-forum.com/t/push/77566/1 "2006-11-28T21:18:34Z")

</div>

I was just prepping a code sample for somebody out in the big wide  
world, and doing that always makes me review my code, and I noticed I  
was using Array#push a lot instead of \<\< (I think that’s Array#\<\<  
actually?).

So, kind of a basic question, is \<\< basically just idiomatic Ruby for  
push? (This was a Rails project with a lot of custom JavaScript and I  
think I just got in that particular mindset.)

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [November 28, 2006, 9:26pm UTC](https://www.ruby-forum.com/t/push/77566/2 "2006-11-28T21:26:37Z")

</div>

Hi –

On Wed, 29 Nov 2006, Giles B. wrote:

> I was just prepping a code sample for somebody out in the big wide  
> world, and doing that always makes me review my code, and I noticed I  
> was using Array#push a lot instead of \<\< (I think that’s Array#\<\<  
> actually?).
> 
> So, kind of a basic question, is \<\< basically just idiomatic Ruby for  
> push? (This was a Rails project with a lot of custom JavaScript and I  
> think I just got in that particular mindset.)

I _think_ the only difference is that push can take more than one  
argument.

David

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [November 28, 2006, 9:36pm UTC](https://www.ruby-forum.com/t/push/77566/3 "2006-11-28T21:36:41Z")

</div>

On Wed, 29 Nov 2006 removed\_email\_address@domain.invalid wrote:

> > push? (This was a Rails project with a lot of custom JavaScript and I  
> > think I just got in that particular mindset.)
> 
> I _think_ the only difference is that push can take more than one  
> argument.

also

\<\< : generally returns self to allow chaining

push : generally returns the elements pushed

-a

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [November 28, 2006, 9:40pm UTC](https://www.ruby-forum.com/t/push/77566/4 "2006-11-28T21:40:42Z")

</div>

Hi –

On Wed, 29 Nov 2006, removed\_email\_address@domain.invalid wrote:

> > >
> 
> push : generally returns the elements pushed

I’m not seeing that:

irb(main):003:0\> [1,2,3].push(4,5)  
=\> [1, 2, 3, 4, 5]  
irb(main):004:0\> [1,2,3] \<\< 4  
=\> [1, 2, 3, 4]

David

---

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [November 29, 2006, 2:03am UTC](https://www.ruby-forum.com/t/push/77566/5 "2006-11-29T02:03:26Z")

</div>

> > > argument.  
> > > =\> [1, 2, 3, 4, 5]  
> > > irb(main):004:0\> [1,2,3] \<\< 4  
> > > =\> [1, 2, 3, 4]

ah, that explains something. I couldn’t open up my old code without  
fiddling with it a bit, but changing \<\< to push() across the board  
killed something in the functionality. I didn’t have time to find out  
exactly what, but I think it’s the only-one-arg thing that did it.
