7) If you will have less than 9 parameters, you can do this:
param_str = temp = 'x1'
10.times do |i|
temp = temp.succ
param_str << ', ' << temp
end
p param_str
--output:--
"x1, x2, x3, x4, x5, x6, x7, x8, x9, y0, y1"
But in ruby, you can define variadic methods:
def my_meth(*args)
args.each {|arg| p arg}
end
my_meth(1, 2, 3)
my_meth('a', 'b', 4)
--output:--
1
2
3
"a"
"b"
4
--
Posted via http://www.ruby-forum.com/.