summaryrefslogtreecommitdiffstats
path: root/content/posts/lesser-known-irb-features
diff options
context:
space:
mode:
Diffstat (limited to 'content/posts/lesser-known-irb-features')
-rw-r--r--content/posts/lesser-known-irb-features/index.org52
1 files changed, 52 insertions, 0 deletions
diff --git a/content/posts/lesser-known-irb-features/index.org b/content/posts/lesser-known-irb-features/index.org
new file mode 100644
index 0000000..0753ae7
--- /dev/null
+++ b/content/posts/lesser-known-irb-features/index.org
@@ -0,0 +1,52 @@
+#+TITLE: Lesser Known IRB Features
+#+DATE: 2023-04-28T00:22:54-04:00
+#+DRAFT: true
+#+DESCRIPTION: Going over some of my favourite lesser known IRB features
+#+TAGS[]: ruby
+#+KEYWORDS[]: ruby
+#+SLUG:
+#+SUMMARY:
+
+While poking around in IRB and looking at the autocompletion results,
+I found some functions that I didn't recognize and decided to take a
+look at what they do. I found some pretty interesting stuff.
+
+It looks like some of these commands have been added recently to come
+up to par with =pry=, and others have been kicking around for a while
+and just flying under the radar.
+
+You can find them all defined in [[https://github.com/ruby/irb/blob/master/lib/irb/extend-command.rb][this file]] in the IRB source code.
+
+- IRB workspaces
+ - The terms workspace/binding/context are used interchangeably
+ - For some reason these methods have an excessive amount of aliases
+ - =pushb <obj>=, =pushws=, =irb_push_workspace=, =irb_push_binding=
+ change the current context (binding) to whatever object you
+ pass as arg. It pushes your binding onto the =workspaces= stack.
+ - =popb=, =popws=, =irb_pop_workspace=, =irb_push_binding= pop your
+ current workspace off the stack and take you out and bring you to
+ your previous binding environment.
+ - =cb [obj]=, =cws=, =chwd=, =irb_cb=, =irb_cws=, =irb_chws=,
+ =irb_change_binding= change the current context without pushing
+ the current context onto the stack, and change to the default
+ context when called without an argument.
+- Examining object internals
+ - =ls [obj]= lists the contents of an object (methods, inherited
+ methods, instance variables, etc.)
+- Switching between multiple IRB sessions (sub-IRBs)
+ - Running =irb= creates a sub-IRB.
+ - =jobs= lists existing sub-IRBs
+ - =fg <num>= lets you change sub-IRB
+ - =kill <num>= kills the given sub-IRB
+- Find the source code for a method or constant
+ - =show_source <obj/method>= Displays the file path a method or
+ object was defined in, and prints its contents
+- Read documentation
+ - =show_doc [method]= Either opens the documentation for the
+ constant or method provided as an argument, or opens an RI
+ documentation prompt of no argument is given.
+- Show the current line
+ - =whereami= lists the current line of execution of the binding.
+ This is useful if you open IRB from =binding.irb= or =binding.b=
+- List internal IRB commands
+ - =show_cmds= lists most of these commands inside of IRB :)