Sha256: d303de5b67fed529bcf4d2685bf5b21e6466acf3a153618381829e263266870b

Contents?: true

Size: 1.31 KB

Versions: 18

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

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

18 entries across 18 versions & 8 rubygems

Version Path
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/byebug-10.0.2/lib/byebug/helpers/var.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/byebug-10.0.2/lib/byebug/helpers/var.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/byebug-10.0.2/lib/byebug/helpers/var.rb
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/byebug-11.0.1/lib/byebug/helpers/var.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/byebug-11.0.1/lib/byebug/helpers/var.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/byebug-11.0.1/lib/byebug/helpers/var.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/byebug-11.0.1/lib/byebug/helpers/var.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/byebug-10.0.2/lib/byebug/helpers/var.rb
byebug-11.0.1 lib/byebug/helpers/var.rb
byebug-11.0.0 lib/byebug/helpers/var.rb
jets-0.5.5 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/helpers/var.rb
jets-0.5.4 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/helpers/var.rb
jets-0.5.3 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/helpers/var.rb
jets-0.5.2 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/helpers/var.rb
jets-0.5.1 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/helpers/var.rb
byebug-10.0.2 lib/byebug/helpers/var.rb
byebug-10.0.1 lib/byebug/helpers/var.rb
byebug-10.0.0 lib/byebug/helpers/var.rb