Sha256: e2c7f9a17cf8215e95809f77c7f21c5230df59cf37d68fcf1142b97d3ce1ff2f

Contents?: true

Size: 1.29 KB

Versions: 16

Compression:

Stored size: 1.29 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|
          [:$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

16 entries across 15 versions & 2 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/byebug-9.0.6/lib/byebug/helpers/var.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/byebug-9.0.6/lib/byebug/helpers/var.rb
tdiary-5.0.4 vendor/bundle/gems/byebug-9.0.6/lib/byebug/helpers/var.rb
byebug-9.0.6 lib/byebug/helpers/var.rb
byebug-9.0.5 lib/byebug/helpers/var.rb
byebug-9.0.4 lib/byebug/helpers/var.rb
byebug-9.0.3 lib/byebug/helpers/var.rb
byebug-9.0.2 lib/byebug/helpers/var.rb
byebug-9.0.1 lib/byebug/helpers/var.rb
byebug-9.0.0 lib/byebug/helpers/var.rb
byebug-8.2.5 lib/byebug/helpers/var.rb
byebug-8.2.4 lib/byebug/helpers/var.rb
byebug-8.2.3 lib/byebug/helpers/var.rb
byebug-8.2.2 lib/byebug/helpers/var.rb
byebug-8.2.1 lib/byebug/helpers/var.rb
byebug-8.2.0 lib/byebug/helpers/var.rb