Override Methods in a Pry Session
Today I learned you can override methods on an object from within pry
! Super helpful if you want to test something out but not change it in code yet. It's important to note this only overrides at the instance level, not the class level, so other instances won't be affected.
class User
def name = "tony"
end
pry(main)> me = User.new
pry(main)> me.name
# => "tony"
pry(main)> def me.name = "who now?"
pry(main)> me.name
# => "who now?"
pry(main)> other_me = User.new
pry(main)> other_me.name
# => "tony"
Tweet