lib/byebug/commands/var/const.rb in byebug-5.0.0 vs lib/byebug/commands/var/const.rb in byebug-6.0.0

- old
+ new

@@ -1,38 +1,49 @@ +require 'byebug/helpers/eval' + module Byebug # # Reopens the +var+ command to define the +const+ subcommand # class VarCommand < Command # # Shows constants # - class ConstSubcommand < Command - def regexp + class ConstCommand < Command + include Helpers::EvalHelper + + self.allow_in_post_mortem = true + + def self.regexp /^\s* c(?:onst)? (?:\s+ (.+))? \s*$/x end + def self.description + <<-EOD + v[ar] c[onstant] + + #{short_description} + EOD + end + + def self.short_description + 'Shows constants of an object.' + end + def execute - str_obj = @match[1] || 'self.class' - obj = bb_warning_eval(str_obj) + obj = single_thread_eval(str_obj) unless obj.is_a?(Module) return errmsg(pr('variable.errors.not_module', object: str_obj)) end - constants = bb_eval("#{str_obj}.constants") + constants = single_thread_eval("#{str_obj}.constants") puts prv(constants.sort.map { |c| [c, obj.const_get(c)] }, 'constant') end - def short_description - 'Shows constants of an object.' - end + private - def description - <<-EOD - v[ar] c[onstant] - - #{short_description} - EOD + def str_obj + @str_obj ||= @match[1] || 'self.class' end end end end