# Simple Question

**URL:** <https://www.ruby-forum.com/t/simple-question/153370>\
**Category:** Ruby\
**Created:** [November 15, 2008, 9:57pm UTC](https://www.ruby-forum.com/t/simple-question/153370 "2008-11-15T21:57:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe-black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joe-black](https://www.ruby-forum.com/u/joe-black)\
**Post date:** [November 15, 2008, 9:57pm UTC](https://www.ruby-forum.com/t/simple-question/153370/1 "2008-11-15T21:57:49Z")

</div>

I saw the following in a book.

def deleted\_roles=(values)  
roles.find(\*values).each(&:destroy)  
end

I understand that this method finds all the roles with the given ids and  
calls destroy on all of them. My question is, what is the significance  
of \*. Why is it roles.find(\*values) and not just plain  
roles.find(values)?

Is there any difference?

Could it possibly be a typo and the method should be defined as

def deleted\_roles(\*values)…

Thanks

---

<div class="post-metadata">

**Author:** ![joe-black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joe-black](https://www.ruby-forum.com/u/joe-black)\
**Post date:** [November 15, 2008, 10:12pm UTC](https://www.ruby-forum.com/t/simple-question/153370/2 "2008-11-15T22:12:26Z")

</div>

- expands an array as multiple arguments. For example, type in an irb  
session:

def find(\*args) # This \* is not the same \* as yours, this is just used  
to collect all the arguments in a single array  
args.each {|x| puts x.class}  
end

find [1,2,3] =\> Array  
find \*[1,2,3] =\> Fixnum three times.

Regards,

Serabe

---

<div class="post-metadata">

**Author:** ![joe-black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joe-black](https://www.ruby-forum.com/u/joe-black)\
**Post date:** [November 15, 2008, 10:19pm UTC](https://www.ruby-forum.com/t/simple-question/153370/3 "2008-11-15T22:19:27Z")

</div>

Hi,

> Is there any difference?
> 
> Could it possibly be a typo and the method should be defined as
> 
> def deleted\_roles(\*values)…

It looks like roles.find expects a list of parameters (i.e. it should  
be invoked like this: roles.find(‘admin’, ‘user’, ‘editor’))  
but deleted\_roles= wants an array (i.e. deleted\_rows = [‘admin’,  
‘user’, ‘editor’])

The \* a.k.a. splat does exactly this conversion - so if someone calls

deleted\_rows = [‘admin’, ‘user’, ‘editor’]

inside the method

roles.find(‘admin’, ‘user’, ‘editor’).each(&:destroy)

will be called (note that the brackets are gone)

HTH,  
Peter

* * *

[http://www.rubyrailways.com](http://www.rubyrailways.com)
