class Pry::CommandState

CommandState is a data structure to hold per-command state.

Pry commands can store arbitrary state here. This state persists between subsequent command invocations. All state saved here is unique to the command.

@since v0.13.0 @api private

Public Class Methods

default() click to toggle source
# File lib/pry/command_state.rb, line 13
def self.default
  @default ||= new
end
new() click to toggle source
# File lib/pry/command_state.rb, line 17
def initialize
  @command_state = {}
end

Public Instance Methods

reset(command_class) click to toggle source
# File lib/pry/command_state.rb, line 25
def reset(command_class)
  @command_state[command_class] = command_struct(command_class)
end
state_for(command_class) click to toggle source
# File lib/pry/command_state.rb, line 21
def state_for(command_class)
  @command_state[command_class] ||= command_struct(command_class)
end

Private Instance Methods

command_struct(command_class) click to toggle source
# File lib/pry/command_state.rb, line 31
def command_struct(command_class)
  Struct.new(:command, *command_class.command_options[:state])
    .new(command: command_class)
end