Sha256: 9c37149e832a5ab5153f29508f634aa32726c0059307c3b49979410eea119366

Contents?: true

Size: 1004 Bytes

Versions: 19

Compression:

Stored size: 1004 Bytes

Contents

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
        <<-EOD
          v[ar] c[onstant]

          #{short_description}
        EOD
      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

Version data entries

19 entries across 18 versions & 3 rubygems

Version Path
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/byebug-9.1.0/lib/byebug/commands/var/const.rb
tdiary-5.0.6 vendor/bundle/gems/byebug-9.1.0/lib/byebug/commands/var/const.rb
byebug-9.1.0 lib/byebug/commands/var/const.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/byebug-9.0.6/lib/byebug/commands/var/const.rb
tdiary-5.0.5 vendor/bundle/gems/byebug-9.0.6/lib/byebug/commands/var/const.rb
tdiary-5.0.4 vendor/bundle/gems/byebug-9.0.6/lib/byebug/commands/var/const.rb
byebug-9.0.6 lib/byebug/commands/var/const.rb
byebug-9.0.5 lib/byebug/commands/var/const.rb
byebug-9.0.4 lib/byebug/commands/var/const.rb
byebug-9.0.3 lib/byebug/commands/var/const.rb
byebug-9.0.2 lib/byebug/commands/var/const.rb
byebug-9.0.1 lib/byebug/commands/var/const.rb
byebug-9.0.0 lib/byebug/commands/var/const.rb
byebug-8.2.5 lib/byebug/commands/var/const.rb
byebug-8.2.4 lib/byebug/commands/var/const.rb
byebug-8.2.3 lib/byebug/commands/var/const.rb
byebug-8.2.2 lib/byebug/commands/var/const.rb
byebug-8.2.1 lib/byebug/commands/var/const.rb
byebug-8.2.0 lib/byebug/commands/var/const.rb