Skip to content

Instantly share code, notes, and snippets.

@edymerchk
Created June 8, 2014 00:24
Show Gist options
  • Save edymerchk/26963e12a3da27263583 to your computer and use it in GitHub Desktop.
Save edymerchk/26963e12a3da27263583 to your computer and use it in GitHub Desktop.
class Person
def self.new(name)
@cache ||= {}
@cache[name] ||= super(name)
end
def initialize(name)
@name = name
end
end
Person.new(:luis) # => #<Person:0x007fccd432f9d0 @name=:luis>
Person.new(:katalina) # => #<Person:0x007fccd43329c8 @name=:katalina>
Person.new(:luis) # => #<Person:0x007fccd432f9d0 @name=:luis>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment