# How to pass unkown length of parameters into a class method

**URL:** <https://www.ruby-forum.com/t/how-to-pass-unkown-length-of-parameters-into-a-class-method/123524>\
**Category:** Ruby\
**Created:** [December 18, 2007, 1:16pm UTC](https://www.ruby-forum.com/t/how-to-pass-unkown-length-of-parameters-into-a-class-method/123524 "2007-12-18T13:16:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jazcyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e56c9b/32.png) [@jazcyk](https://www.ruby-forum.com/u/jazcyk)\
**Post date:** [December 18, 2007, 1:16pm UTC](https://www.ruby-forum.com/t/how-to-pass-unkown-length-of-parameters-into-a-class-method/123524/1 "2007-12-18T13:16:48Z")

</div>

#!/usr/bin/ruby  
class Example  
def Examplemethod(var1)  
puts var1  
end  
end

Check = Example.new  
Check.Examplemethod(“Loftz”)

Hey guys

So this is just calling a method that prints out a name. Im just  
wondering can i specify that there may be mulitple parameters going into  
this method

for example  
Check.Example(“Loftz”,“peter”,“john”,“paul”,“gary”)

and have that method inside the class Example not know how many  
parameters are going to be passed into it?

def Examplemethod(?)

Regards  
Loftz

---

<div class="post-metadata">

**Author:** ![jazcyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e56c9b/32.png) [@jazcyk](https://www.ruby-forum.com/u/jazcyk)\
**Post date:** [December 18, 2007, 1:34pm UTC](https://www.ruby-forum.com/t/how-to-pass-unkown-length-of-parameters-into-a-class-method/123524/2 "2007-12-18T13:34:41Z")

</div>

def Example(\*args)  
args.each do |arg|  
# Process individual argument  
end  
end

Jason

---

<div class="post-metadata">

**Author:** ![jazcyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e56c9b/32.png) [@jazcyk](https://www.ruby-forum.com/u/jazcyk)\
**Post date:** [December 18, 2007, 7:11pm UTC](https://www.ruby-forum.com/t/how-to-pass-unkown-length-of-parameters-into-a-class-method/123524/3 "2007-12-18T19:11:04Z")

</div>

Just to elaborate a little on Jason’s point, for those who are  
interested in what this code is doing, it is based on Ruby’s extremely  
cool array assignment feature. This is explained here:

[http://phrogz.net/ProgrammingRuby/tut\_expressions.html#parallelassignment](http://phrogz.net/ProgrammingRuby/tut_expressions.html#parallelassignment)

and applies to parameter assignment in method invocations as well, as  
Jason pointed out:

[http://phrogz.net/ProgrammingRuby/tut\_methods.html#variablelengthargumentlists](http://phrogz.net/ProgrammingRuby/tut_methods.html#variablelengthargumentlists)

That is to say, that variable argument lists in Ruby is actually using  
nested assignment, which you can use anywhere, not just in method  
definitions.

## Best of luck, -Dan

[http://dev.zeraweb.com/](http://dev.zeraweb.com/)
