class ActionDispatch::Flash::FlashHash

def keep(k = nil)

flash.keep(:notice) # keeps only the "notice" entry, the rest of the flash is discarded
flash.keep # keeps the entire flash

Keeps either the entire current flash or a specific flash entry available for the next action:
def keep(k = nil)
  k = k.to_s if k
  @discard.subtract Array(k || keys)
  k ? self[k] : self
end