Sha256: 25c885ae65fde0c3d1ece82551ada69fab42764e13f31e01aaac9c16c365f3ac

Contents?: true

Size: 1.41 KB

Versions: 17

Compression:

Stored size: 1.41 KB

Contents

require 'byebug/command'
require 'byebug/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
      <<-EOD
        disp[lay][ <expression>]

        #{short_description}

        If <expression> specified, adds <expression> into display expression
        list. Otherwise, it lists all expressions.
      EOD
    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
      '(undefined)'
    end
  end
end

Version data entries

17 entries across 16 versions & 3 rubygems

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