Rails - Local Variables versus Instance Variables

前端 未结 2 979
误落风尘
误落风尘 2020-12-29 07:53

while learning Rails, I keep hearing Local vs Instance but I can\'t find a definition of the two & the differences. And I\'d like to avoid making assumptions.

Wh

相关标签:
2条回答
  • 2020-12-29 08:08

    The main differences between local and instance variables are as follows

    1. local variable has its scope restriction i.e not available to another methods where as instance available to another
    2. local and instance variable is also available in view
    3. instance variable is separate for each object
    0 讨论(0)
  • 2020-12-29 08:14

    The main difference between local and instance variable is that local variable is only available in controller, where as instance variable is available in corresponding views also. The controller and views do not share local variables.

    Thanks, Anubhaw

    0 讨论(0)
提交回复
热议问题