class Racket::Registry
Public Class Methods
Returns a new registry with all items in the map registered as non-singleton procs.
@param [Hash] map @return [Racket::Registry]
# File lib/racket/registry.rb, line 31 def with_map(map) registry = new map.each_pair { |key, value| registry.register(key, value) } registry end
Returns a new registry with all items in the map registered as singleton procs.
@param [Hash] map @return [Racket::Registry]
# File lib/racket/registry.rb, line 42 def with_singleton_map(map) registry = new map.each_pair { |key, value| registry.register_singleton(key, value) } registry end
Public Instance Methods
Removes the callback specified by key
from the registry.
@param [String|Symbol] key @return [nil]
# File lib/racket/registry.rb, line 55 def forget(key) Helper.forget(obj: self, key: key) end
Removes all callbacks from the registry.
# File lib/racket/registry.rb, line 60 def forget_all Helper.forget_all(obj: self) end
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.
@param [String|Symbol] key @param [Proc|nil] proc @return [nil]
# File lib/racket/registry.rb, line 73 def register(key, proc = nil, &block) Helper.register(obj: self, key: key, proc: proc, block: block) end
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.
@param [String|Symbol] key @param [Proc|nil] proc @return [nil]
# File lib/racket/registry.rb, line 86 def register_singleton(key, proc = nil, &block) Helper.register_singleton(obj: self, key: key, proc: proc, block: block) end