Permalink
Browse files

Use class (instead of class name) as identity map key

  • Loading branch information...
1 parent c1cb8a2 commit 5e2eff8db4118b328c02924e21b828a539d1e518 @sferik committed Jun 3, 2012
Showing with 6 additions and 6 deletions.
  1. +3 −3 lib/twitter/base.rb
  2. +3 −3 lib/twitter/identifiable.rb
View
6 lib/twitter/base.rb
@@ -24,8 +24,8 @@ def self.lazy_attr_reader(*attrs)
end
def self.new(attrs={})
- @@identity_map[self.name] ||= {}
- @@identity_map[self.name][Marshal.dump(attrs)] || super(attrs)
+ @@identity_map[self] ||= {}
+ @@identity_map[self][Marshal.dump(attrs)] || super(attrs)
end
# Initializes a new object
@@ -34,7 +34,7 @@ def self.new(attrs={})
# @return [Twitter::Base]
def initialize(attrs={})
self.update(attrs)
- @@identity_map[self.class.name][Marshal.dump(attrs)] = self
+ @@identity_map[self.class][Marshal.dump(attrs)] = self
end
# Fetches an attribute of an object using hash notation
View
6 lib/twitter/identifiable.rb
@@ -4,8 +4,8 @@ module Twitter
class Identifiable < Base
def self.new(attrs={})
- @@identity_map[self.name] ||= {}
- attrs['id'] && @@identity_map[self.name][attrs['id']] ? @@identity_map[self.name][attrs['id']].update(attrs) : super(attrs)
+ @@identity_map[self] ||= {}
+ attrs['id'] && @@identity_map[self][attrs['id']] ? @@identity_map[self][attrs['id']].update(attrs) : super(attrs)
end
# Initializes a new object
@@ -15,7 +15,7 @@ def self.new(attrs={})
def initialize(attrs={})
if attrs['id']
self.update(attrs)
- @@identity_map[self.class.name][attrs['id']] = self
+ @@identity_map[self.class][attrs['id']] = self
else
super
end

0 comments on commit 5e2eff8

Please sign in to comment.