it looks very odd when passing these many parameters. Is there any other
option that I can mention only mandatory args in the method & remaining
all are in single argument or something like that?
it looks very odd when passing these many parameters. Is there any other
option that I can mention only mandatory args in the method & remaining
all are in single argument or something like that?
Yes, you can do this:
def method1(required, required, required, *args)
Which Ruby will fill *args with remaining arguments as an array (empty array if there are none):
def test(a,b,*args)
p a,b,args
end
=> nil
test(1,2,3,4,5)
1
2
[3, 4, 5]
Another option is to pass either an object in, or a Hash. I'd recommend this path if the data you're dealing with relates to each other (which it looks like it does).
it looks very odd when passing these many parameters. Is there any other
option that I can mention only mandatory args in the method & remaining
all are in single argument or something like that?
Another option is to pass either >an object in, or a Hash. I'd >recommend
this path if the data >you're dealing with relates to >each other (which it
looks like it >does).
+1
Read about a code smell named Primitive Obsession. If the set of params are
part of a higher level concept of your program, such as UserContact or
something similar, you should create an object for that. It can be a full
fledged class or a struct, for example.