Class: Card::Codename
- Inherits:
-
Object
- Object
- Card::Codename
- Defined in:
- lib/card/codename.rb
Overview
Card's names can be changed, and therefore names should not be directly mentioned in code, lest a name change break the application. Instead, a Card that needs specific code manipulations should be given a Codename, a unique string identifier that will not change even if the card's name does.
The Codename class provides a fast cache for this slow-changing data. Every process maintains a complete cache that is not frequently reset
Generally speaking, codenames are represented by Symbols, names are Strings, and ids are Integers.
Class Method Summary collapse
-
.[](key) ⇒ String, Integer
returns codename for id and id for codename.
-
.codehash ⇒ Hash
a Hash in which String keys have Integer values and vice versa.
-
.reset_cache ⇒ Object
clear cache both locally and in cache.
Class Method Details
.[](key) ⇒ String, Integer
returns codename for id and id for codename
23 24 25 26 |
# File 'lib/card/codename.rb', line 23 def [] key return if key.nil? codehash[key.is_a?(Integer) ? key : key.to_sym] end |
.codehash ⇒ Hash
a Hash in which String keys have Integer values and vice versa
30 31 32 |
# File 'lib/card/codename.rb', line 30 def codehash @codehash ||= load_codehash end |