Skip to content

Instantly share code, notes, and snippets.

@weapp
Created July 21, 2014 17:10
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 weapp/6a13a4a723d96e9d8c2b to your computer and use it in GitHub Desktop.
Save weapp/6a13a4a723d96e9d8c2b to your computer and use it in GitHub Desktop.
# http://www.rubytapas.com/episodes/7-Constructors
class RpsMove
def self.new(move)
@cache ||= {}
@cache[move] ||= super(move)
end
def initialize(move)
@move = move
end
end
puts RpsMove.new(:rock).inspect
puts RpsMove.new(:paper).inspect
puts RpsMove.new(:rock).inspect
puts RpsMove.new(:paper).inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment