Ruby - when to use instance variables vs parameters between methods?

Posted by Michael Durrant on Programmers See other posts from Programmers or by Michael Durrant
Published on 2013-10-18T14:55:16Z Indexed on 2013/10/18 16:11 UTC
Read the original article Hit count: 242

Filed under:
|
|

I'm writing several methods that call other methods.

To pass the information I have a couple of choices:

  1. Pass the information as parameters

  2. 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?

© Programmers or respective owner

Related posts about object-oriented

Related posts about ruby