# Order of arguments

**URL:** <https://www.ruby-forum.com/t/order-of-arguments/146945>\
**Category:** Ruby\
**Created:** [August 27, 2008, 12:45am UTC](https://www.ruby-forum.com/t/order-of-arguments/146945 "2008-08-27T00:45:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Kless](https://www.ruby-forum.com/u/Kless)\
**Post date:** [August 27, 2008, 12:45am UTC](https://www.ruby-forum.com/t/order-of-arguments/146945/1 "2008-08-27T00:45:27Z")

</div>

## if I define a function with several args. as

## def func(foo, bar)

## and is used with the changed args.:

## func(bar=‘wrong’, foo=‘order’)\*

it will change the order of args. and this is not desirable, how to  
solve it?

I imagine this with a lot of args. and could be danger

---

<div class="post-metadata">

**Author:** ![Kless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Kless](https://www.ruby-forum.com/u/Kless)\
**Post date:** [August 27, 2008, 2:51am UTC](https://www.ruby-forum.com/t/order-of-arguments/146945/2 "2008-08-27T02:51:12Z")

</div>

Kless wrote:

> func(bar=‘wrong’, foo=‘order’)

Supplementing Joel’s answer - that code is a Ruby fallacy and should be  
avoided.  
It does not name the arguments as they go in. It assigns two new  
variables into  
the calling scope - very confusingly.

---

<div class="post-metadata">

**Author:** ![Kless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Kless](https://www.ruby-forum.com/u/Kless)\
**Post date:** [August 27, 2008, 12:53am UTC](https://www.ruby-forum.com/t/order-of-arguments/146945/3 "2008-08-27T00:53:39Z")

</div>

Kless wrote:

> I imagine this with a lot of args. and could be danger

Use a hash argument

def func(args={})  
bar=args[:bar]  
foo=args[:foo]  
end

func(:bar=\>1, :foo=\>2)

---

<div class="post-metadata">

**Author:** ![Kless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cc9497/32.png) [@Kless](https://www.ruby-forum.com/u/Kless)\
**Post date:** [August 27, 2008, 9:39am UTC](https://www.ruby-forum.com/t/order-of-arguments/146945/4 "2008-08-27T09:39:48Z")

</div>

Kless wrote:

> it will change the order of args. and this is not desirable, how to  
> solve it?

It will not. In Ruby, the order of passed arguments is the order of  
received arguments, always. Your struct, as it was said, defines two  
useless local variables, and in fact passes them to the function.
