Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we access/manipulate variable names which conflicts with byebug reserved keywords?

Tags:

ruby

byebug

How do we access those variable names which conflict with byebug reserved name?

(byebug) var local
h = {"hierarchyId"=>"59f0b029e4b037ef11a055f7", "level"=>2, ...
self =                   <div class="index_as_table"></div>

(byebug) 

I want to access variable "h"

but typing h would show up the "help dialog box for byebug"

(byebug) h

  break      -- Sets breakpoints in the source code
  catch      -- Handles exception catchpoints
  condition  -- Sets conditions on breakpoints
  continue   -- Runs until program ends, hits a breakpoint or reaches a line
  debug      -- Spawns a subdebugger
  delete     -- Deletes breakpoints
  disable    -- Disables breakpoints or displays
  display    -- Evaluates expressions every time the debugger stops
  down       -- Moves to a lower frame in the stack trace
  edit       -- Edits source files
  enable     -- Enables breakpoints or displays
  finish     -- Runs the program until frame returns
  frame      -- Moves to a frame in the call stack
  help       -- Helps you using byebug
  history    -- Shows byebug's history of commands
  info       -- Shows several informations about the program being debugged
  interrupt  -- Interrupts the program
  irb        -- Starts an IRB session
  kill       -- Sends a signal to the current process
  list       -- Lists lines of source code
  method     -- Shows methods of an object, class or module
  next       -- Runs one or more lines of code
  pry        -- Starts a Pry session
  quit       -- Exits byebug
  restart    -- Restarts the debugged program
  save       -- Saves current byebug session to a file
  set        -- Modifies byebug settings
  show       -- Shows byebug settings
  source     -- Restores a previously saved byebug session
  step       -- Steps into blocks or methods one or more times
  thread     -- Commands to manipulate threads
  tracevar   -- Enables tracing of a global variable
  undisplay  -- Stops displaying all or some expressions when program stops
  untracevar -- Stops tracing a global variable
  up         -- Moves to a higher frame in the stack trace
  var        -- Shows variables and its values
  where      -- Displays the backtrace

(byebug) 

Is there any way to access variables who conflicts with these reserved keyword names. like exclamation prefix in python's pdb? (!h didn't work for byebug)

like image 485
enator Avatar asked Dec 06 '17 05:12

enator


People also ask

How do I get out of Byebug?

To exit byebug , use the quit command (abbreviated to q ). Normally, if you are in an interactive session, this command will prompt to ask if you really want to quit. If you want to quit without being prompted, enter quit unconditionally (abbreviated to q! ).

How to use byebug?

wherever you'd like the application to "break" - that is, executing byebug is equivalent to putting a breakpoint in your code. Run the program and use the debugger commands once you reach the breakpoint. near the end. Restart your server.


2 Answers

You can surround it in parentheses:

[1, 4] in /Users/max/test.rb
   1: require 'byebug'
   2:
   3: byebug
=> 4: false
(byebug) (h = 1)
1
(byebug) (h)
1
(byebug)
like image 55
max pleaner Avatar answered Oct 09 '22 18:10

max pleaner


You can use:

eval h

Byebug Guide: https://github.com/deivid-rodriguez/byebug/blob/master/GUIDE.md

like image 36
Abdullah Avatar answered Oct 09 '22 19:10

Abdullah