### Start IRB Session Source: https://github.com/ruby/irb/blob/master/doc/Index.md Demonstrates how to start an IRB session and execute basic Ruby expressions, including multi-line input for class definitions. ```console $ irb irb(main):001> 1 + 2 => 3 irb(main):002* class Foo irb(main):003* def foo irb(main):004* puts 1 irb(main):005* end irb(main):006> end => :foo irb(main):007> Foo.new.foo 1 => nil ``` -------------------------------- ### Install IRB Gem Source: https://github.com/ruby/irb/blob/master/doc/Index.md Instructions for installing the IRB gem using Bundler or directly via the gem command. ```ruby gem 'irb' ``` ```console $ bundle $ gem install irb ``` -------------------------------- ### Install IRB Gem Source: https://github.com/ruby/irb/blob/master/README.md Instructions for installing the IRB gem using Bundler or directly via the `gem` command. ```ruby gem 'irb' ``` ```shell $ bundle $ gem install irb ``` -------------------------------- ### Start IRB Session Source: https://github.com/ruby/irb/blob/master/README.md Demonstrates how to start an IRB session from the shell and execute basic Ruby expressions. ```shell $ irb irb(main):001> 1 + 2 => 3 irb(main):002* class Foo irb(main):003* def foo irb(main):004* puts 1 irb(main):005* end irb(main):006> end => :foo irb(main):007> Foo.new.foo 1 => nil ``` -------------------------------- ### Install libvterm Source: https://github.com/ruby/irb/blob/master/CONTRIBUTING.md Installs the libvterm library using Homebrew, which is required for running IRB's integration tests. ```bash brew install libvterm ``` -------------------------------- ### Enabling Type-Based Completion (repl_type_completor) Source: https://github.com/ruby/irb/blob/master/doc/Index.md Details how to enable IRB's experimental type-based completion using the `repl_type_completor` gem. This provides more advanced completion suggestions compared to the default RegexpCompletor. Installation can be done via `gem install repl_type_completor` or by adding it to the Gemfile. Activation is possible via the `--type-completor` command-line option, setting `IRB.conf[:COMPLETOR] = :type` in `.irbrc`, or setting the `IRB_COMPLETOR` environment variable. ```console $ gem install repl_type_completor ``` ```ruby gem 'repl_type_completor', group: [:development, :test] ``` ```console $ irb --type-completor ``` ```ruby IRB.conf[:COMPLETOR] = :type # default is :regexp ``` ```ruby ENV['IRB_COMPLETOR'] = 'type' IRB.start ``` -------------------------------- ### Run IRB Integration Tests Source: https://github.com/ruby/irb/blob/master/CONTRIBUTING.md Installs dependencies and runs IRB's integration tests (yamatanooroti) after libvterm is installed. ```bash WITH_VTERM=1 bundle install WITH_VTERM=1 bundle exec rake test test_yamatanooroti ``` -------------------------------- ### Configuration Monitor Setup Source: https://github.com/ruby/irb/blob/master/doc/Configurations.md Explains how to set up a configuration monitor using `IRB.conf[:IRB_RC]` to track changes to IRB configuration. ```ruby IRB.conf[:IRB_RC] = proc {|conf| puts conf.class } ``` ```APIDOC Configuration Monitor: You can monitor changes to the configuration by assigning a proc to `IRB.conf[:IRB_RC]` in the configuration file: Each time the configuration is changed, that proc is called with argument `conf`: ``` -------------------------------- ### Using binding.irb as a Breakpoint Source: https://github.com/ruby/irb/blob/master/doc/Index.md Shows how to use `binding.irb` within a Ruby program to pause execution and start an IRB session with the current context. ```ruby def greet(word) binding.irb puts "Hello #{word}" end greet("World") ``` ```console $ ruby test.rb From: test.rb @ line 2 : 1: def greet(word) => 2: binding.irb 3: puts "Hello #{word}" 4: end 5: 6: greet("World") irb(main):001> word => "World" irb(main):002> exit Hello World ``` -------------------------------- ### Use binding.irb as Breakpoint Source: https://github.com/ruby/irb/blob/master/README.md Shows how to use `binding.irb` within a Ruby program to start an IRB session with the current execution context. ```ruby def greet(word) binding.irb puts "Hello #{word}" end greet("World") ``` -------------------------------- ### Type-Based Completion Examples Source: https://github.com/ruby/irb/blob/master/doc/Index.md Illustrates scenarios where IRB::TypeCompletor excels over IRB::RegexpCompletor, such as completing chained methods, block parameters, and methods on objects resulting from method calls. It also highlights that TypeCompletor uses runtime information for completion. ```ruby irb(main):001> 'Ruby'.upcase.chars.s # Array methods (sample, select, shift, size) ``` ```ruby irb(main):001> 10.times.map(&:to_s).each do |s| irb(main):002> s.up # String methods (upcase, upcase!, upto) ``` ```ruby irb(main):001> class User < ApplicationRecord irb(main):002> def foo irb(main):003> sa # save, save! ``` ```ruby def f(arg = [0, 'a'].sample) if arg.is_a?(String) arg. # Completes both Integer and String methods ``` ```ruby irb(main):001> a = [1] => [1] irb(main):002> a.first. # Completes Integer methods ``` -------------------------------- ### Extra RI Documentation Directories Source: https://github.com/ruby/irb/blob/master/doc/Configurations.md Explains how to specify paths for RI documentation directories to be loaded at startup using `conf.extra_doc_dirs`, command-line options, or hash entries. ```console irb(main):001> conf.extra_doc_dirs => [] ``` ```console $ irb --extra-doc-dir your_doc_dir --extra-doc-dir my_doc_dir irb(main):001> conf.extra_doc_dirs => ["your_doc_dir", "my_doc_dir"] ``` ```ruby IRB.conf[:EXTRA_DOC_DIRS] = %w[your_doc_dir my_doc_dir] ``` ```APIDOC RI Documentation Directories: You can specify the paths to RI documentation directories that are to be loaded (in addition to the default directories) at startup; see details about RI by typing `ri --help`. Array `conf.extra_doc_dirs` determines the directories (if any) that are to be loaded during session startup. The array is used only during session startup, so the initial value is the only one that counts. The default initial value is `[]` (load no extra documentation): You can set the default initial value via: - Command-line option `--extra_doc_dir` - Hash entry `IRB.conf[:EXTRA_DOC_DIRS] = *array*`: Note that the configuration file entry overrides the command-line options. ``` -------------------------------- ### Live Help System: help command Source: https://github.com/ruby/irb/blob/master/doc/COMPARED_WITH_PRY.md Describes the live help system commands. Both IRB and Pry support a `help` command for accessing live help. However, IRB does not yet support detailed descriptions for individual commands. ```ruby help ``` ```ruby command_name --help ``` -------------------------------- ### Loading Modules in IRB Source: https://github.com/ruby/irb/blob/master/doc/Configurations.md Describes how to specify modules to be required at startup using `conf.load_modules`, command-line options, or hash entries. ```console irb(main):001> conf.load_modules => [] ``` ```console $ irb -r csv -r json irb(main):001> conf.load_modules => ["csv", "json"] ``` ```ruby IRB.conf[:LOAD_MODULES] = %w[csv json] ``` ```APIDOC Load Modules: You can specify the names of modules that are to be required at startup. Array `conf.load_modules` determines the modules (if any) that are to be required during session startup. The array is used only during session startup, so the initial value is the only one that counts. The default initial value is `[]` (load no modules): You can set the default initial value via: - Command-line option `-r` - Hash entry `IRB.conf[:LOAD_MODULES] = *array*`: Note that the configuration file entry overrides the command-line options. ``` -------------------------------- ### Debugging with `binding.irb` and `debug.gem` Source: https://github.com/ruby/irb/blob/master/doc/Index.md Illustrates how to initiate a debugging session within IRB using `binding.irb` and the `debug` command. It shows how to navigate code, inspect variables, and use IRB commands alongside debugger commands. ```ruby def greet(word) binding.irb puts "Hello #{word}" end greet("World") ``` ```console From: test.rb @ line 3 : 1: 2: def greet(word) => 3: binding.irb 4: puts "Hello #{word}" 5: end 6: 7: greet("World") irb(main):001> debug irb:rdbg(main):002> ``` ```console irb:rdbg(main):002> info %self = main _ = nil word = "World" irb:rdbg(main):003> next [1, 7] in test.rb 1| 2| def greet(word) 3| => 4| 5| 6| 7| greet("World") =>#0 Object#greet(word="World") at test.rb:4 #1
at test.rb:7 irb:rdbg(main):004> ``` ```console irb:rdbg(main):004> show_source greet From: test.rb:2 def greet(word) binding.irb puts "Hello #{word}" end ``` -------------------------------- ### IRB Commands Reference Source: https://github.com/ruby/irb/blob/master/doc/Index.md Provides a comprehensive list of commands available in IRB, categorized by functionality such as general commands, workspace management, debugging, and miscellaneous utilities. Each command is briefly described. ```APIDOC Help: help List all available commands. Use `help ` to get information about a specific command. IRB: context Displays current configuration. exit Exit the current irb session. exit! Exit the current process. irb_load Load a Ruby file. irb_require Require a Ruby file. source Loads a given file in the current session. irb_info Show information about IRB. history [-g [query] | -G [query]] Shows the input history. `-g [query]` or `-G [query]` allows you to filter the output. disable_irb Disable binding.irb. Workspace: cwws Show the current workspace. chws Change the current workspace to an object. workspaces Show workspaces. pushws Push an object to the workspace stack. popws Pop a workspace from the workspace stack. cd Move into the given object or leave the current context. Multi-irb (DEPRECATED): irb Start a child IRB. jobs List of current sessions. fg Switches to the session of the given number. kill Kills the session with the given number. Debugging: debug Start the debugger of debug.gem. break Start the debugger of debug.gem and run its `break` command. catch Start the debugger of debug.gem and run its `catch` command. next Start the debugger of debug.gem and run its `next` command. delete Start the debugger of debug.gem and run its `delete` command. step Start the debugger of debug.gem and run its `step` command. continue Start the debugger of debug.gem and run its `continue` command. finish Start the debugger of debug.gem and run its `finish` command. backtrace Start the debugger of debug.gem and run its `backtrace` command. info Start the debugger of debug.gem and run its `info` command. Misc: edit Open a file or source location. measure [off] `measure` enables the mode to measure processing time. `measure :off` disables it. copy Copy expression output to clipboard Context: show_doc Look up documentation with RI. ls Show methods, constants, and variables. show_source Show the source code of a given method, class/module, or constant. whereami Show the source code around binding.irb again. Helper methods: conf Returns the current IRB context. Aliases: $ Alias for `show_source` @ Alias for `whereami` ``` -------------------------------- ### IRB Command-Line Arguments Source: https://github.com/ruby/irb/blob/master/doc/Index.md Illustrates how command-line arguments are passed to IRB and how the `--` option treats subsequent arguments literally. ```console $ irb --noscript Foo Bar Baz irb(main):001> ARGV => ["Foo", "Bar", "Baz"] irb(main):002> exit $ $ irb --noscript -- --noscript -- Foo Bar Baz irb(main):001> ARGV => ["--noscript", "--", "Foo", "Bar", "Baz"] irb(main):002> exit $ ``` -------------------------------- ### IRB Console Features vs. debug.gem Source: https://github.com/ruby/irb/blob/master/doc/Index.md Compares the features of the IRB console integration with the native console provided by debug.gem, highlighting IRB's advantages like access to specific commands, multi-line input, symbol shortcuts, autocompletion, and prompt customization. ```APIDOC IRB Console Advantages: - Access to IRB commands: `show_source`, `show_doc` - Multi-line input support - Symbol shortcuts: `@` for `whereami`, `$` for `show_source` - Autocompletion - Customizable prompt IRB Console Limitations: - Does not support `pre` and `do` arguments (unlike `binding.break`) - No remote connection support (cannot be used with `debug.gem`'s remote debugging) - Previous return value access via `_` is not supported ``` -------------------------------- ### Configure IRB Command Aliases Source: https://github.com/ruby/irb/blob/master/doc/Index.md Explains how to manage command aliases in IRB. It covers viewing current aliases, setting initial aliases in the configuration file, and dynamically modifying them during a session. ```APIDOC conf.command_aliases Returns a hash of the current command aliases. Example: irb(main):001> conf.command_aliases => {:"$"=>:show_source, :"@"=>:whereami} IRB.conf[:COMMAND_ALIASES] = {alias_name: :command_name, ...} Sets initial command aliases in the IRB configuration file. Example: IRB.conf[:COMMAND_ALIASES] = {foo: :show_source, bar: :whereami} conf.command_aliases = new_aliases_hash Replaces the current command aliases with the provided hash. ``` -------------------------------- ### Code Browsing: show_source vs. show-source Source: https://github.com/ruby/irb/blob/master/doc/COMPARED_WITH_PRY.md Details the commands used for browsing source code in IRB and Pry. IRB's `show_source` command is functional but cannot display C source code, unlike Pry's `show-source`. ```ruby show_source ``` ```ruby show-source ``` -------------------------------- ### Generate IRB Documentation Locally Source: https://github.com/ruby/irb/blob/master/CONTRIBUTING.md Generates the IRB documentation site locally using RDoc. Includes a command to force regeneration. ```bash bundle exec rake rdoc bundle exec rake rerdoc # to force regeneration ``` -------------------------------- ### Document Browsing: show_doc vs. ri Source: https://github.com/ruby/irb/blob/master/doc/COMPARED_WITH_PRY.md Compares the commands for accessing documentation. IRB uses `show_doc`, while Pry uses `ri` for document browsing. ```ruby show_doc ``` ```ruby ri ``` -------------------------------- ### IRB Encoding Configuration Source: https://github.com/ruby/irb/blob/master/doc/Index.md Explains how to configure encodings for the IRB console using command-line options. ```APIDOC Encoding Configuration: Command-line option `-E *ex*[:*in*]`: Sets initial external (ex) and internal (in) encodings. Command-line option `-U`: Sets both external and internal encodings to UTF-8. ``` -------------------------------- ### IRB Initialization Precedence Source: https://github.com/ruby/irb/blob/master/doc/Configurations.md Explains the precedence rules for IRB configuration, where entries in `IRB.conf` override command-line options. ```APIDOC Notes on Initialization Precedence: - Any conflict between an entry in hash `IRB.conf` and a command-line option is resolved in favor of the hash entry. - Hash `IRB.conf` affects the context only once, when the configuration file is interpreted; any subsequent changes to it do not affect the context and are therefore essentially meaningless. ``` -------------------------------- ### IRB Configuration Options Source: https://github.com/ruby/irb/blob/master/doc/Configurations.md Details various configuration settings for IRB, such as color highlighting, loader, tracer, pager, verbosity, and main object. ```APIDOC IRB Configuration Options: - :USE_COLORIZE: Whether to use color highlighting. Initial value: `true`. - :USE_LOADER: Whether to use the IRB loader for `require` and `load`. Initial value: `false`. - :USE_TRACER: Whether to use the IRB tracer. Initial value: `false`. - :USE_PAGER: Controls whether pager is enabled. Initial value: `true`. - :VERBOSE: Whether to print verbose output. Initial value: `nil`. - :__MAIN__: The main IRB object. Initial value: `main`. ``` -------------------------------- ### Debugging with debug.gem and IRB Source: https://github.com/ruby/irb/blob/master/README.md Explains how to integrate IRB with the `debug.gem` for advanced debugging, including using the `debug` command within `binding.irb` or setting an environment variable. ```shell # Inside binding.irb: # debug # Or set environment variable: RUBY_DEBUG_IRB_CONSOLE=1 ruby your_script.rb ``` -------------------------------- ### IRB Configuration Sources and File Path Resolution Source: https://github.com/ruby/irb/blob/master/doc/Configurations.md Explains the hierarchy of IRB configuration sources (command-line, config file, environment variables, IRB.conf) and the order in which IRB searches for its configuration file (.irbrc, irb.rc, etc.). It also mentions the `conf.rc?` method. ```APIDOC IRB Configuration Sources: 1. Command-Line Options 2. Configuration File 3. Environment Variables 4. Hash `IRB.conf` Configuration File Path Resolution Order: 1. `$IRBRC` 2. `$XDG_CONFIG_HOME/irb/irbrc` 3. `$HOME/.irbrc` 4. `$HOME/.config/irb/irbrc` 5. `.irbrc` in current directory 6. `irb.rc` in current directory 7. `_irbrc` in current directory 8. `$irbrc` in current directory Method `conf.rc?`: Returns `true` if a configuration file was read, `false` otherwise. Hash entry `IRB.conf[:RC]`: Contains the value of whether a configuration file was read. ``` -------------------------------- ### Pry Navigation Commands Source: https://github.com/ruby/irb/blob/master/doc/COMPARED_WITH_PRY.md Details Pry's workspace navigation commands, including `cd object` to enter an object and `cd ..` to leave the current object. The `nesting` command lists nesting levels. ```ruby cd object ``` ```ruby cd .. ``` ```ruby nesting ``` -------------------------------- ### Input History Support in IRB Source: https://github.com/ruby/irb/blob/master/doc/COMPARED_WITH_PRY.md Details the input history features available in IRB, including comprehensive support and the 'history' command. It also notes planned improvements and areas where contributions are welcome. ```ruby Supports retrieving previous input and the `history` command ``` -------------------------------- ### Editor Integration: edit command Source: https://github.com/ruby/irb/blob/master/doc/COMPARED_WITH_PRY.md Highlights the command for opening methods in editors. Both IRB and Pry use the `edit` command for this functionality. ```ruby edit ``` -------------------------------- ### IRB Navigation Commands Source: https://github.com/ruby/irb/blob/master/doc/COMPARED_WITH_PRY.md Details IRB's workspace navigation commands, including `pushws` to enter an object, `popws` to leave, and `workspaces` to list nesting levels. The `cd object` and `cd ..` commands are also supported since version 1.14.0. ```ruby pushws object ``` ```ruby popws ``` ```ruby workspaces ``` ```ruby cd object ``` ```ruby cd .. ``` -------------------------------- ### Runtime Invocation: binding.irb vs. binding.pry Source: https://github.com/ruby/irb/blob/master/doc/COMPARED_WITH_PRY.md Compares the runtime invocation methods for IRB and Pry. `binding.irb` is used to enter IRB at the current binding, while `binding.pry` is the equivalent for Pry. ```ruby binding.irb ``` ```ruby binding.pry ``` -------------------------------- ### Configure IRB Input History Source: https://github.com/ruby/irb/blob/master/doc/Index.md Details how to configure the input command history in IRB, including setting the history file path and the number of commands to save. This configuration can be done via the IRB configuration file or dynamically during a session. ```APIDOC IRB.conf[:HISTORY_FILE] = *filepath* Sets the filepath for storing IRB command history. conf.history_file Returns the current history file path. conf.history_file = *new_filepath* Copies the current history to the specified new_filepath and sets it as the active history file for the session. IRB.conf[:SAVE_HISTORY] = *n* Controls the number of commands saved in the history. - Positive integer: Saves the specified number of commands. - Negative integer: Saves all commands. - Zero or nil: Disables saving commands. conf.save_history Retrieves the current setting for the number of commands to save. conf.save_history = *new_count* Changes the number of commands to save for the current session. ``` -------------------------------- ### Registering a Custom IRB Command Source: https://github.com/ruby/irb/blob/master/doc/EXTEND_IRB.md Demonstrates how to create and register a custom command in IRB. This involves defining a class that inherits from `IRB::Command::Base`, specifying its category, description, and help message, and then registering it using `IRB::Command.register`. ```ruby require "irb/command" class Greet < IRB::Command::Base category "Greeting" description "Greets the user" help_message <<~HELP Greets the user with the given name. Usage: greet HELP # Any input after the command name will be passed as a single string. # If nothing is added after the command, an empty string will be passed. def execute(arg) puts "Hello! #{arg}" end end IRB::Command.register(:greet, Greet) ``` -------------------------------- ### Configure IRB Input Method Source: https://github.com/ruby/irb/blob/master/doc/Index.md Sets the input method for IRB sessions. Options include Reline, Readline, and Stdio, configurable via IRB.conf or command-line arguments. ```ruby IRB.conf[:USE_SINGLELINE] = true IRB.conf[:USE_MULTILINE] = false # Sets input method to IRB::ReadlineInputMethod ``` ```ruby IRB.conf[:USE_SINGLELINE] = false IRB.conf[:USE_MULTILINE] = true # Sets input method to IRB::RelineInputMethod ``` ```console --singleline --nomultiline # Sets input method to IRB::ReadlineInputMethod ``` ```console --nosingleline --multiline # Sets input method to IRB::RelineInputMethod ``` ```console --nosingleline --nomultiline # Sets input method to IRB::StdioInputMethod ``` -------------------------------- ### IRB.conf Configuration Options Source: https://github.com/ruby/irb/blob/master/doc/Configurations.md Details the various configuration options available within the IRB.conf hash. These options control aspects like application name, indentation, history saving, prompt styles, and more. ```APIDOC IRB.conf: A hash containing configuration options for IRB. Entries: :AP_NAME: Description: IRB application name. Initial Value: 'irb' :AT_EXIT: Description: Array of hooks to call at exit. Initial Value: [] :AUTO_INDENT: Description: Whether automatic indentation is enabled. Initial Value: true :BACK_TRACE_LIMIT: Description: Sets the back trace limit. Initial Value: 16 :COMMAND_ALIASES: Description: Defines input command aliases. Initial Value: { "$": :show_source, "@": :whereami } :CONTEXT_MODE: Description: Sets the context mode (type of binding for statement evaluation). Initial Value: 4 :ECHO: Description: Whether to print return values (echoing). Initial Value: nil (sets conf.echo to true) :ECHO_ON_ASSIGNMENT: Description: Whether to print return values on assignment. Initial Value: nil (sets conf.echo_on_assignment to :truncate) :EVAL_HISTORY: Description: How much evaluation history to store. Initial Value: nil :EXTRA_DOC_DIRS: Description: Array of RI documentation directories to parse. Initial Value: [] :IGNORE_EOF: Description: Whether to ignore end-of-file. Initial Value: false :IGNORE_SIGINT: Description: Whether to ignore SIGINT. Initial Value: true :INSPECT_MODE: Description: Whether to use method `inspect` for printing return values. Initial Value: true :IRB_LIB_PATH: Description: The path to the IRB library directory. Initial Value: "RUBY_DIR/lib/ruby/gems/RUBY_VER_NUM/gems/irb-IRB_VER_NUM/lib/irb" :IRB_NAME: Description: IRB name. Initial Value: 'irb' :IRB_RC: Description: Configuration monitor. Initial Value: nil :LC_MESSAGES: Description: Locale. Initial Value: IRB::Locale object :LOAD_MODULES: Description: Deprecated. :MAIN_CONTEXT: Description: The context for the main IRB session. Initial Value: IRB::Context object :MEASURE: Description: Whether to measure performance. Initial Value: false :MEASURE_CALLBACKS: Description: Callback methods for performance measurement. Initial Value: [] :MEASURE_PROC: Description: Procs for performance measurement. Initial Value: { :TIME=>#, :STACKPROF=># } :PROMPT: Description: Hash of defined prompts. Initial Value: { :NULL=>{ :PROMPT_I=>nil, :PROMPT_S=>nil, :PROMPT_C=>nil, :RETURN=>"%s\n" }, :DEFAULT=>{ :PROMPT_I=>"%N(%m):%03n> ", :PROMPT_S=>"%N(%m):%03n%l ", :PROMPT_C=>"%N(%m):%03n* ", :RETURN=>"=> %s\n" }, :CLASSIC=>{ :PROMPT_I=>"%N(%m):%03n:%i> ", :PROMPT_S=>"%N(%m):%03n:%i%l ", :PROMPT_C=>"%N(%m):%03n:%i* ", :RETURN=>"%s\n" }, :SIMPLE=>{ :PROMPT_I=>">> ", :PROMPT_S=>"%l> ", :PROMPT_C=>"?> ", :RETURN=>"=> %s\n" }, :INF_RUBY=>{ :PROMPT_I=>"%N(%m):%03n> ", :PROMPT_S=>nil, :PROMPT_C=>nil, :RETURN=>"%s\n", :AUTO_INDENT=>true }, :XMP=>{ :PROMPT_I=>nil, :PROMPT_S=>nil, :PROMPT_C=>nil, :RETURN=>" ==>%s\n" } } :PROMPT_MODE: Description: Name of current prompt. Initial Value: :DEFAULT :RC: Description: Whether a configuration file was found and interpreted. Initial Value: true if found, false otherwise. :SAVE_HISTORY: Description: Number of commands to save in input command history. Initial Value: 1000 :SINGLE_IRB: Description: Whether command-line option --single-irb was given. Initial Value: true if given, false otherwise. :USE_AUTOCOMPLETE: Description: Whether to use automatic completion. Initial Value: true ``` -------------------------------- ### Extending IRB Functionality Source: https://github.com/ruby/irb/blob/master/doc/Index.md Provides information on how to extend IRB's functionality using official APIs available in versions 1.13.0 and later. ```APIDOC Extending IRB: Versions `v1.13.0` and later allow users/libraries to extend IRB functionality through official APIs. Refer to `EXTEND_IRB.md` for detailed information. ``` -------------------------------- ### Debugger Integration with pry-byebug Source: https://github.com/ruby/irb/blob/master/doc/COMPARED_WITH_PRY.md This snippet describes how to integrate the pry-byebug gem for debugging within the IRB environment. It highlights the dependency on the pry-byebug gem for enhanced debugging capabilities. ```ruby With `byebug` through [pry-byebug](https://github.com/deivid-rodriguez/pry-byebug) gem ``` -------------------------------- ### Debugger Integration with irb:rdbg Source: https://github.com/ruby/irb/blob/master/doc/COMPARED_WITH_PRY.md This snippet outlines the debugger integration using IRB's built-in 'irb:rdbg' functionality. It provides a link to further details on using this debugging method. ```ruby Supports [`irb:rdbg`](https://github.com/ruby/irb#debugging-with-irb) sessions ``` -------------------------------- ### Registering a Custom IRB Helper Method Source: https://github.com/ruby/irb/blob/master/doc/EXTEND_IRB.md Illustrates how to define and register a custom helper method in IRB. This requires creating a class that inherits from `IRB::HelperMethod::Base`, defining its description and execution logic, and then registering it with `IRB::HelperMethod.register`. ```ruby # This only loads the minimum components required to define and register a helper method. # It does not load the entire IRB, nor does it initialize it. require "irb/helper_method" class MyHelper < IRB::HelperMethod::Base description "This is a test helper" def execute(arg, kwarg:) "arg: #{arg}, kwarg: #{kwarg}" end end IRB::HelperMethod.register(:my_helper, MyHelper) ``` -------------------------------- ### IRB Environment Variables Source: https://github.com/ruby/irb/blob/master/doc/Configurations.md Lists and describes environment variables that can be used to customize IRB's behavior, including colorization, autocompletion, editor preferences, configuration file location, pager, and locale settings. ```APIDOC Environment Variables for IRB Configuration: - `NO_COLOR`: Disables colorization. - `IRB_USE_AUTOCOMPLETE`: Set to `false` to disable autocompletion. - `IRB_COMPLETOR`: Configures autocompletion behavior (`regexp` or `type`). - `IRB_COPY_COMMAND`: Overrides the default program for system clipboard interaction. - `VISUAL` / `EDITOR`: Specifies the editor for the `edit` command. - `IRBRC`: Specifies the rc-file for configuration. - `XDG_CONFIG_HOME`: Used to locate the rc-file if `IRBRC` is unset. - `RI_PAGER` / `PAGER`: Specifies the pager for documentation. - `IRB_LANG`, `LC_MESSAGES`, `LC_ALL`, `LANG`: Determines the locale. ``` -------------------------------- ### IRB Command-Line Options Source: https://github.com/ruby/irb/blob/master/doc/COMMAND_LINE_OPTIONS.md Lists and describes the command-line options for IRB, including their functionality and related rdoc references. These options control IRB's behavior, such as debugging, encoding, file loading, and output formatting. ```APIDOC -d: Set $DEBUG and $VERBOSE to true. -E _ex_[:_in_]: Set initial external (ex) and internal (in) encodings (same as ruby -E). -f: Don't initialize from configuration file. -I _dirpath_: Specify LOAD_PATH directory (same as ruby -I). -r _load-module_: Require load-module (same as ruby -r). -U: Set external and internal encodings to UTF-8. -w: Suppress warnings (same as ruby -w). -W[_level_]: Set warning level; 0=silence, 1=medium, 2=verbose (same as ruby -W). --autocomplete: Use auto-completion. --back-trace-limit _n_: Set a backtrace limit; display at most the top `n` and bottom `n` entries. --colorize: Use color-highlighting for input and output. --context-mode _n_: Select method to create Binding object for new workspace; `n` in range `0..4`. --echo: Print return values. --extra-doc-dir _dirpath_: Add a documentation directory for the documentation dialog. --inf-ruby-mode: Set prompt mode to :INF_RUBY (appropriate for `inf-ruby-mode` on Emacs); suppresses --multiline and --singleline. --inspect: Use method `inspect` for printing return values. --multiline: Use the multiline editor as the input method. --noautocomplete: Don't use auto-completion. --nocolorize: Don't use color-highlighting for input and output. --noecho: Don't print return values. --noecho-on-assignment: Don't print result on assignment. --noinspect: Don't use method `inspect` for printing return values. --nomultiline: Don't use the multiline editor as the input method. --noprompt: Don't print prompts. --noscript: Treat the first command-line argument as a normal command-line argument, and include it in ARGV. --nosingleline: Don't use the singleline editor as the input method. --noverbose: Don't print verbose details. --prompt _mode_, --prompt-mode _mode_: Set prompt and return formats; `mode` may be a pre-defined prompt or the name of a custom prompt. --script: Treat the first command-line argument as the path to an initialization script, and omit it from ARGV. --simple-prompt, --sample-book-mode: Set prompt mode to :SIMPLE. --singleline: Use the singleline editor as the input method. --tracer: Use Tracer to print a stack trace for each input command. --truncate-echo-on-assignment: Print truncated result on assignment. --verbose: Print verbose details. -v, --version: Print the IRB version. -h, --help: Print the IRB help text. --: Separate options from arguments on the command-line. ```