Sha256: 8dac1f0283ff6b731a540187f35547a52dc64f4b19eaf30fdd015aede215535c

Contents?: true

Size: 1.48 KB

Versions: 6770

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require_relative "../command"
require_relative "../helpers/eval"

module Byebug
  #
  # Custom expressions to be displayed every time the debugger stops.
  #
  class DisplayCommand < Command
    include Helpers::EvalHelper

    self.allow_in_post_mortem = false
    self.always_run = 2

    def self.regexp
      /^\s* disp(?:lay)? (?:\s+ (.+))? \s*$/x
    end

    def self.description
      <<-DESCRIPTION
        disp[lay][ <expression>]

        #{short_description}

        If <expression> specified, adds <expression> into display expression
        list. Otherwise, it lists all expressions.
      DESCRIPTION
    end

    def self.short_description
      "Evaluates expressions every time the debugger stops"
    end

    def execute
      return print_display_expressions unless @match && @match[1]

      Byebug.displays.push [true, @match[1]]
      display_expression(@match[1])
    end

    private

    def display_expression(exp)
      print pr("display.result", n: Byebug.displays.size,
                                 exp: exp,
                                 result: eval_expr(exp))
    end

    def print_display_expressions
      result = prc("display.result", Byebug.displays) do |item, index|
        active, exp = item

        { n: index + 1, exp: exp, result: eval_expr(exp) } if active
      end

      print result
    end

    def eval_expr(expression)
      error_eval(expression).inspect
    rescue StandardError
      "(undefined)"
    end
  end
end

Version data entries

6,770 entries across 6,767 versions & 30 rubygems

Version Path
cybrid_api_id_ruby-0.123.104 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_organization_ruby-0.123.104 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_organization_ruby-0.123.103 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_bank_ruby-0.123.103 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_id_ruby-0.123.103 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_bank_ruby-0.123.101 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_id_ruby-0.123.101 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_organization_ruby-0.123.101 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_bank_ruby-0.123.100 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_id_ruby-0.123.100 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_organization_ruby-0.123.100 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
ory-client-1.15.16 vendor/bundle/ruby/3.1.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_bank_ruby-0.123.99 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_id_ruby-0.123.99 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_organization_ruby-0.123.99 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_bank_ruby-0.123.98 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_organization_ruby-0.123.98 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_id_ruby-0.123.98 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_bank_ruby-0.123.97 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb
cybrid_api_organization_ruby-0.123.97 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/commands/display.rb