In a Rails application, sometimes you may wanna use global variables for every request, with which you don’t have to send the object as a parameter everywhere, like
current_user for model layers (which may not be a good idea).
So how could we do that?
Ruby Global Variables
If you know Ruby well, you may know variable with a beginning with
$ is global.
But global variables with
$ prefix are supposed to be accessible from every single palce of your code, so they are shared among all threads, and that’s definitely not what we want, right?
So basically, don’t use Ruby native global variables, ever.