class Racket::Registry

Racket Registry namespace

Public Class Methods

singleton_map(map)
Alias for: with_singleton_map
with_map(map) click to toggle source

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
with_singleton_map(map) click to toggle source

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
Also aliased as: singleton_map

Public Instance Methods

forget(key) click to toggle source

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
forget_all() click to toggle source

Removes all callbacks from the registry.

# File lib/racket/registry.rb, line 60
def forget_all
  Helper.forget_all(obj: self)
end
register(key, proc = nil, &block) click to toggle source

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
register_singleton(key, proc = nil, &block) click to toggle source

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
Also aliased as: singleton
singleton(key, proc = nil, &block)
Alias for: register_singleton