Class: PryCommandSetRegistry::Registry
- Inherits:
-
Object
- Object
- PryCommandSetRegistry::Registry
- Defined in:
- lib/pry_command_set_registry/registry.rb
Overview
A registry of command sets and descriptions of those command sets.
Instance Attribute Summary collapse
-
#command_sets ⇒ Hash{String => PryCommandSetRegistry::CommandSet}
readonly
The Hash mapping of all registered command sets.
Instance Method Summary collapse
-
#command_set(name) ⇒ PryCommandSetRegistry::CommandSet?
Attempts to look up a registered command set with the given name.
-
#define_command_set(name, description, options = {}) { ... } ⇒ PryCommandSetRegistry::CommandSet
Helper method for defining a command set and registering it immediately.
-
#initialize ⇒ PryCommandSetRegistry::Registry
constructor
Creates a new command set registry.
Constructor Details
#initialize ⇒ PryCommandSetRegistry::Registry
Creates a new command set registry.
10 11 12 |
# File 'lib/pry_command_set_registry/registry.rb', line 10 def initialize @command_sets = {} end |
Instance Attribute Details
#command_sets ⇒ Hash{String => PryCommandSetRegistry::CommandSet} (readonly)
The Hash mapping of all registered command sets.
6 7 8 |
# File 'lib/pry_command_set_registry/registry.rb', line 6 def command_sets @command_sets end |
Instance Method Details
#command_set(name) ⇒ PryCommandSetRegistry::CommandSet?
Attempts to look up a registered command set with the given name. If the name starts with a colon, the colon is removed prior to lookup.
22 23 24 25 |
# File 'lib/pry_command_set_registry/registry.rb', line 22 def command_set(name) sanitized_name = name.to_s.sub(/^:/, "") command_sets[sanitized_name] end |
#define_command_set(name, description, options = {}) { ... } ⇒ PryCommandSetRegistry::CommandSet
Helper method for defining a command set and registering it immediately. All arguments are passed directly to CommandSet#initialize to instantiate a new command set.
54 55 56 57 58 |
# File 'lib/pry_command_set_registry/registry.rb', line 54 def define_command_set(name, description, = {}, &block) command_set = CommandSet.new(name, description, , &block) command_sets[command_set.name] = command_set command_set end |