1

Is there an efficient or a shorter way to achieve the same result as below?

params[:random] = split_array(params[:random])

I want to pass a variable as parameter to a rails method and store the result in the same variable and use it further?

For example, I was thinking something similar to

variable = variable + 1 

can be efficiently written as

variable++
A.A. F
  • 349
  • 5
  • 16

1 Answers1

1

What you were saying could be achieved if you passed params[:random] by reference, but that is not achievable in ruby since ruby is strictly pass by value.

The line params[:random] = split_array(params[:random]) is perfectly fine (not very verbose).

Lucas Wieloch
  • 818
  • 7
  • 19
  • Note: even if you found a way of passing by reference in ruby, you should not. If that line really will be a problem to your code readability (e.g. if you are using it in many lines), maybe there is an object or something else missing in your code architecture; but that is just speculation on my side – Lucas Wieloch Jul 11 '19 at 08:55