The Interactive Ruby Shell, or IRB, doesn’t have a way to clear all variables that I am aware of besides quitting irb and then restarting irb however you can simulate this by invoking subirbs. Subirbs are jobs underneath the main irb session that will allow you to work within irb on different code at the same time without having to stop irb and restart it. So you can load certain gems from the main irb session and not be required to reload them for each subirb. Below are some examples of how subirbs or irb jobs are used.
The Interactive Ruby Shell, or irb, is a great tool to use when debugging Ruby code. You can launch it from a shell window and quickly determine where errors in your Ruby code. Obviously irb is not always the best tool to use when debugging a large code base however for quick hints to where errors are in your Ruby code irb will save the day. One thing I noticed was sometimes when creating arrays irb would output the entire array even if you have not called for that output. So I was thinking it would be nice to be able to toggle the verbose output of arrays on or off during troubleshooting. The verbose output of irb is typically very useful so this toggle should only be used in some scenarios. Below is an explanation of how to create a toggle to turn the irb context echo on or off.
When debugging Rails, I often open up an iRb shell by typing
This command lists all instance methods in the User model, excluding inherited methods and sorts them in alphabetical order.
I will add more useful iRb methods as I discover and remember them
If you want to dynamically add a member to a Ruby object, use the hash/array brackets and symbol (:user_id) as shown in the iRb session below. As you can see the dot notation will not work. bash >> d = AccessMode.find(1) => #<AccessMode id: 1, device_id: 31218, mode: "dialup", timestamp: "2007-12-25 15:52:55"> >> d[:user_id] =…
Error: /usr/local/lib/ruby/1.8/irb/completion.rb:10:in `require’: no such file to load — readline (LoadError)
When attempting to run irb you get the above error.