Skip to content

Instantly share code, notes, and snippets.

@tjvc
Last active December 29, 2023 10:01
Show Gist options
  • Save tjvc/1bb3c4105a50ccdd7db0471d183d86bf to your computer and use it in GitHub Desktop.
Save tjvc/1bb3c4105a50ccdd7db0471d183d86bf to your computer and use it in GitHub Desktop.
true or false?
# Assume a Rails app with a User model. Assign a User instance to a
# variable, remove and reload the model class constant (simulating code
# reloading in development) and test equality of the cached instance and
# another of the same record. True or false?
cached_user = User.find(1)
Object.send(:remove_const, :User)
load 'app/models/user.rb'
cached_user == User.find(1)
@dorianmarie
Copy link

true

@dorianmarie
Copy link

require_relative "config/environment"

cached_user = User.find(1)

Object.send(:remove_const, :User)
load 'app/models/user.rb'

p cached_user == User.find(1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment