Skip to content

Instantly share code, notes, and snippets.

@judofyr
Created April 8, 2014 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save judofyr/10128699 to your computer and use it in GitHub Desktop.
Save judofyr/10128699 to your computer and use it in GitHub Desktop.
def extract_session
envs = ObjectSpace.each_object(Hash).lazy.select { |env| env.key?("rack.version") && env.key?("rack.session") }
before = envs.to_a
GC.disable
yield
after = (envs.to_a - before)
raise "Could not extract session" unless after.size == 1
after.first['rack.session']
ensure
GC.enable
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment