January 9 2020
Ruby Tip: Local Variables from Unexecuted Code
Recently, I had a bug where I reassigned
params in a Rails controller but only for development mode. However, when I pushed to production, I found
params would become nil after passing this unexecuted code.
As it turns out, this is a feature of Ruby: “The local variable is created when the parser encounters the assignment, not when the assignment occurs”. (Ruby documentation)