How long does an instance variable persist? In Rails? In Java? In PHP?

后端 未结 3 1039
礼貌的吻别
礼貌的吻别 2021-01-16 00:49

If I instantiate a class and set an instance variable in a Ruby module used by a Rails controller or model, how long does that instance variable persist? Does a variable nee

3条回答
  •  粉色の甜心
    2021-01-16 01:27

    In Ruby on Rails, it always depends on the scope and where it's defined.

    For example, objects/instance variables defined in your environment and configuration files, will persist always. A simple example of this is ActiveMerchant payment gateways, which are defined in the environment.rb file and are present for every request.

    In case of controllers, it present for that HTTP request alone, the object and the instance variables.

提交回复
热议问题