class Byebug::DisplayCommand - byebug-11.0.1 Documentation

# class Byebug::DisplayCommand

Custom expressions to be displayed every time the debugger stops.

### Public Class Methods

description() click to toggle source

    # File lib/byebug/commands/display.rb, line 20
        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

regexp() click to toggle source

    # File lib/byebug/commands/display.rb, line 16
    def self.regexp
      /^\s* disp(?:lay)? (?:\s+ (.+))? \s*$/x
    end

short_description() click to toggle source

    # File lib/byebug/commands/display.rb, line 31
    def self.short_description
      "Evaluates expressions every time the debugger stops"
    end

### Public Instance Methods

execute() click to toggle source

    # File lib/byebug/commands/display.rb, line 35
    def execute
      return print_display_expressions unless @match && @match[1]

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

### Private Instance Methods

display_expression(exp) click to toggle source

    # File lib/byebug/commands/display.rb, line 44
    def display_expression(exp)
      print pr("display.result", n: Byebug.displays.size,
                                 exp: exp,
                                 result: eval_expr(exp))
    end

eval_expr(expression) click to toggle source

    # File lib/byebug/commands/display.rb, line 60
    def eval_expr(expression)
      error_eval(expression).inspect
    rescue StandardError
      "(undefined)"
    end

print_display_expressions() click to toggle source

    # File lib/byebug/commands/display.rb, line 50
    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