/
const.rb
51 lines (40 loc) · 1.03 KB
/
const.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true
require "byebug/helpers/eval"
module Byebug
#
# Reopens the +var+ command to define the +const+ subcommand
#
class VarCommand < Command
#
# Shows constants
#
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
<<-DESCRIPTION
v[ar] c[onstant]
#{short_description}
DESCRIPTION
end
def self.short_description
"Shows constants of an object."
end
def execute
obj = warning_eval(str_obj)
unless obj.is_a?(Module)
return errmsg(pr("variable.errors.not_module", object: str_obj))
end
constants = warning_eval("#{str_obj}.constants")
puts prv(constants.sort.map { |c| [c, obj.const_get(c)] }, "constant")
end
private
def str_obj
@str_obj ||= @match[1] || "self.class"
end
end
end
end