D
D
Demigodd2019-09-16 09:06:58
ruby
Demigodd, 2019-09-16 09:06:58

How to reduce the number of function arguments?

The code:

def my_function(one, two, three, four)
# To Do Something
end

The problem with this function is that the number of arguments can increase, and it turns out that it's not nice to add so many arguments of almost the same type.
Tell me some universal and beautiful way to do this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton R., 2019-09-16
@Demigodd

Create an array with arguments and refer to the indexes in the function body.
Function Test($array)
{
$result = $array[0] + $array[1];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question