Skip to content

Instantly share code, notes, and snippets.

@mattetti
Created December 2, 2009 19:29
Show Gist options
  • Save mattetti/247468 to your computer and use it in GitHub Desktop.
Save mattetti/247468 to your computer and use it in GitHub Desktop.
# solution provided by Eloy Duran
class API
def self.get(id)
new(with_response_data)
end
end
class APIWithIdentityMap < API
def self.map
Thread.current[:map][self] ||= {}
end
def self.get(id)
map[id] ||= super
end
end
def session
Thread.current[:map] = {}
yield
ensure
Thread.current[:map] = nil
end
session do
# logic that performs requests
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment