Sha256: 9856014e613656ba09486da49b21c04baa00eac3210e5a6f2edb2e5831a144a3

Contents?: true

Size: 1 KB

Versions: 6

Compression:

Stored size: 1 KB

Contents

# 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)
        return errmsg(pr("variable.errors.not_module", object: str_obj)) unless obj.is_a?(Module)

        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

Version data entries

6 entries across 6 versions & 4 rubygems

Version Path
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/byebug-11.0.1/lib/byebug/commands/var/const.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/byebug-11.0.1/lib/byebug/commands/var/const.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/byebug-11.0.1/lib/byebug/commands/var/const.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/byebug-11.0.1/lib/byebug/commands/var/const.rb
byebug-11.0.1 lib/byebug/commands/var/const.rb
byebug-11.0.0 lib/byebug/commands/var/const.rb