state.rb 733 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # module that keeps track of the state of the game
  2. # Just so no global variables are needed...
  3. module State
  4. class << self
  5. def prepare_registry
  6. @registry ||= {}
  7. end
  8. def get(name)
  9. prepare_registry
  10. return @registry[name.to_sym]
  11. end
  12. def put(name, value)
  13. prepare_registry
  14. return @registry[name.to_sym] = value
  15. end
  16. def [](name)
  17. prepare_registry
  18. return get(name)
  19. end
  20. def []=(name, value)
  21. prepare_registry
  22. return put(name, value)
  23. end
  24. def method_missing(name, *args)
  25. names = name.to_s
  26. if names[-1] == '='
  27. self.put(names[0, names.size - 1], *args)
  28. else
  29. self.get(names)
  30. end
  31. end
  32. end
  33. end