If you declare a method that takes two parameters, on This method call , you need to pass two parameters along with it.
But, Ruby facilitates to declare methods that can work with a variable number of parameters.
Example
def evon (*t)
puts "The number of parameters is #{t.length}"
for i in 0...t.length
puts "The parameters are #{t[i]}"
end
end
evon "Abhishek", "23", "M","B.tech"
evon "Pranav", "21", "M", "B.tech"
Output
The number of parameters is 4
The parameters are Abhishek
The parameters are 23
The parameters are B.tech
The number of parameters is 4
The parameters are Pranav
The parameters are 21
The parameters are M
The parameters are B.tech
0 Comment(s)