Sha256: 748a5feac62cf5c99053bf34e74d2e5ccece3c8613608f689610876a1dfbb2a7

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

require 'byebug/helpers/eval'

module Byebug
  module Helpers
    #
    # Utilities for variable subcommands
    #
    module VarHelper
      include EvalHelper

      def var_list(ary, binding = context.frame._binding)
        vars = ary.sort.map do |name|
          [name, safe_inspect(silent_eval(name.to_s, binding))]
        end

        puts prv(vars, 'instance')
      end

      def var_global
        globals = global_variables.reject do |v|
          %i[$IGNORECASE $= $KCODE $-K $binding].include?(v)
        end

        var_list(globals)
      end

      def var_instance(str)
        obj = warning_eval(str || 'self')

        var_list(obj.instance_variables, obj.instance_eval { binding })
      end

      def var_local
        locals = context.frame.locals
        cur_self = context.frame._self
        locals[:self] = cur_self unless cur_self.to_s == 'main'
        puts prv(locals.keys.sort.map { |k| [k, locals[k]] }, 'instance')
      end

      def var_args
        args = context.frame.args
        return if args == [[:rest]]

        all_locals = context.frame.locals
        arg_values = args.map { |arg| arg[1] }

        locals = all_locals.select { |k, _| arg_values.include?(k) }
        puts prv(locals.keys.sort.map { |k| [k, locals[k]] }, 'instance')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/byebug-9.1.0/lib/byebug/helpers/var.rb
tdiary-5.0.6 vendor/bundle/gems/byebug-9.1.0/lib/byebug/helpers/var.rb
byebug-9.1.0 lib/byebug/helpers/var.rb