How do I create a Ruby function that does not have an explicit number of parameters?
More clarification needed?
Use *rest
. here's a nice little tutorial.
Use the splat operator *
def foo(a,b,c,*others) # this function has at least three arguments, # but might have more puts a puts b puts c puts others.join(',') end foo(1,2,3,4,5,6,7,8,9) # prints: # 1 # 2 # 3 # 4,5,6,7,8,9
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With