narayya chowdary
Joined: 09 May 2008 Posts: 24
|
Posted: Fri Aug 01, 2008 3:55 am Post subject: In ruby allows variable no of parameters to a function |
|
|
Ruby allows to pass variable number of parameters to a function.
Following is the example for this.
def fun(*my_string)
my_string.each do |word|
puts word
end
end
fun('hello','naresh')
fun()
o/p:- hello
naresh
The asterisk is actually taking all arguments you send to the method and assigning them to an array named my_string. As you can see, by making use of the asterisk, we’re even able to pass in zero arguments. |
|