Ruby Use keyword parameters
Use keyword parameters
# ruby lets you have keyword parameters
def test (a=1, b=2, c=a+b)
puts "#{a}, #{b}, #{c}"
end
# invocations w/ and w/o arguments
test
test 5
test 4, 6
test 3, 4, 6
# Extra arguments are gathered into the last variable if
# proceded with a "*". (each " is an iterator that loops over
# its members
def test(a=1,b=2,*c)
puts "#{a},#{b}"
c.each{|x| print " #{x}, "}
end
test
test 3
test 3, 6
test 3, 6, 9, 12, 15, 18