# Question about a multiple assignment statement used in Rails

**URL:** <https://www.ruby-forum.com/t/question-about-a-multiple-assignment-statement-used-in-rails/65145>\
**Category:** Ruby\
**Created:** [August 16, 2006, 3:38pm UTC](https://www.ruby-forum.com/t/question-about-a-multiple-assignment-statement-used-in-rails/65145 "2006-08-16T15:38:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 16, 2006, 3:38pm UTC](https://www.ruby-forum.com/t/question-about-a-multiple-assignment-statement-used-in-rails/65145/1 "2006-08-16T15:38:19Z")

</div>

As I’m very much still a ruby newbie, I’m hoping someone can help me to  
correctly parse the following statement generated by Rails scaffolding:

@category\_pages, @categories = paginate :category, :per\_page =\> 10

This statement occurs in the following context:

class CategoriesController \< ApplicationController  
.  
.  
.  
def list  
@category\_pages, @categories = paginate :category, :per\_page =\> 10  
end  
.  
.  
.  
end

Now, I know that paginate is a method of the ActionController class,  
but is it being called with two arguments or one? And if it is being  
called with two arguments (:category, :per\_page =\> 10), how is  
multi-assignment working here?

To me, this looks like @category\_pages will get the return value of the  
paginate method, and @categories will be assigned the value nil.

Any advice on how to correctly understand this assignment statement  
would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 16, 2006, 3:56pm UTC](https://www.ruby-forum.com/t/question-about-a-multiple-assignment-statement-used-in-rails/65145/2 "2006-08-16T15:56:25Z")

</div>

On 8/16/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> .  
> called with two arguments (:category, :per\_page =\> 10), how is  
> multi-assignment working here?
> 
> To me, this looks like @category\_pages will get the return value of the  
> paginate method, and @categories will be assigned the value nil.
> 
> Any advice on how to correctly understand this assignment statement  
> would be greatly appreciated.

let’s simplify it:

var1, var2 = fnc :sym1, :sym2 =\> 10

1. the right-hand side: function’s arguments are divided in two  
groups: non-hash and hash. all the hash args are passed as one hash,  
as last argument (also there can be a special argument &block, that  
will take the block if any was passed).  
So the call is equivalent to: fnc(:sym1, {:sym2 =\>10})

2, now the left-hand side: if fnc returns an array (what I suppose is  
the case), the array can be automatically split into items:

a, b = [1,2] #=\> a == 1, b == 2

So that’s it.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [August 17, 2006, 12:07am UTC](https://www.ruby-forum.com/t/question-about-a-multiple-assignment-statement-used-in-rails/65145/3 "2006-08-17T00:07:08Z")

</div>

Jan S. wrote:

> a, b = [1,2] =\> a == 1, b == 2
> 
> So that’s it.

Ah, I see. The method returns an object with multiple values that get  
unpacked by the multi-assignment.

That’s very cool, but a bit obtuse. I think I can learn to like it,  
though ;).

Thanks
