Background
I have a method which in which I want to modify a number which will be passed into the method, but not returned.
Example
def increase_number_by_one_and_do_some_other_stuff(number)
number = number + 1
some_other_stuff = "Other stuff I want to happen in this function"
some_other_stuff
end
number = 1
increase_number_by_one_and_do_some_other_stuff(number)
puts number
# => 1
## Expecting 2
Is there any way to achieve this in Ruby, or is it always Pass by Value? I have tried to understand exactly how object references/values are treated in Ruby, but for my level of experience it's quite confusing still.
More context
The situation I'm trying to use it is something like this. Tried to keep it simple but still give enough information.
total = 1000
unaccounted_for = 100
accounted_for = total - unaccounted_for
distribute_unaccounted(unaccounted_for, accounted_for)
puts unaccounted_for
# => 55
puts accounted_for
# => 945
def distributed_unaccounted(unaccounted_for, accounted_for)
# lots of code
category_a_reaccounted = 25 # calculated within this method
category_b_reaccounted = 20 # calculated within this method
total_reaccounted = category_a_reaccounted + category_b_reaccounted
unaccounted_for -= total_reaccounted
accounted_for += total_reaccounted
end