Ruby - when to use instance variables vs parameters between methods?
- by Michael Durrant
I'm writing several methods that call other methods.
To pass the information I have a couple of choices:
Pass the information as parameters
Set instance variables so that other methods can access them
When should I choose one option over the other?
It seems that the first option is good as it is very specific about what is being passed. the downside seems to be that a lot of values are being passed around.
The second method doesn't require passing all the values around but seems to lead to a lot of magic where methods set instance variables 'somewhere'
Should I always be very explicit about gets passed to other methods in the class? Are there exceptions so this?