Class: Racket::Registry
- Inherits:
-
Object
- Object
- Racket::Registry
- Defined in:
- lib/racket/registry.rb
Overview
Racket Registry namespace
Defined Under Namespace
Classes: InvalidCallbackError, InvalidKeyError, KeyAlreadyRegisteredError, KeyNotRegisteredError
Class Method Summary collapse
-
.with_map(map) ⇒ Racket::Registry
Returns a new registry with all items in the map registered as non-singleton procs.
-
.with_singleton_map(map) ⇒ Racket::Registry
(also: singleton_map)
Returns a new registry with all items in the map registered as singleton procs.
Instance Method Summary collapse
-
#forget(key) ⇒ nil
Removes the callback specified by
keyfrom the registry. -
#forget_all ⇒ Object
Removes all callbacks from the registry.
-
#register(key, proc = nil, &block) ⇒ nil
Registers a new callback in the registry.
-
#register_singleton(key, proc = nil, &block) ⇒ nil
(also: #singleton)
Registers a new callback in the registry.
Class Method Details
.with_map(map) ⇒ Racket::Registry
Returns a new registry with all items in the map registered as non-singleton procs.
29 30 31 32 33 |
# File 'lib/racket/registry.rb', line 29 def with_map(map) registry = new map.each_pair { |key, value| registry.register(key, value) } registry end |
.with_singleton_map(map) ⇒ Racket::Registry Also known as: singleton_map
Returns a new registry with all items in the map registered as singleton procs.
40 41 42 43 44 |
# File 'lib/racket/registry.rb', line 40 def with_singleton_map(map) registry = new map.each_pair { |key, value| registry.register_singleton(key, value) } registry end |
Instance Method Details
#forget(key) ⇒ nil
Removes the callback specified by key from the registry.
53 54 55 |
# File 'lib/racket/registry.rb', line 53 def forget(key) Helper.forget(obj: self, key: key) end |
#forget_all ⇒ Object
Removes all callbacks from the registry.
58 59 60 |
# File 'lib/racket/registry.rb', line 58 def forget_all Helper.forget_all(obj: self) end |
#register(key, proc = nil, &block) ⇒ nil
Registers a new callback in the registry. This will add a new method matching key to the registry that can be used both outside the registry and when registering other callbacks dependant of the current entry. Results from the callback will not be cached, meaning that the callback may return a different object every time.
71 72 73 |
# File 'lib/racket/registry.rb', line 71 def register(key, proc = nil, &block) Helper.register(obj: self, key: key, proc: proc, block: block) end |
#register_singleton(key, proc = nil, &block) ⇒ nil Also known as: singleton
Registers a new callback in the registry. This will add a new method matching key to the registry that can be used both outside the registry and when registering other callbacks dependant of the current entry. Results from the callnack will be cached, meaning that the callback will return the same object every time.
84 85 86 |
# File 'lib/racket/registry.rb', line 84 def register_singleton(key, proc = nil, &block) Helper.register_singleton(obj: self, key: key, proc: proc, block: block) end |