(https://github.com/ruby/irb/pull/971)
It's essentially a combination of pushws and popws commands that are
easier to use.
Help message:
```
Usage: cd ([target]|..)
IRB uses a stack of workspaces to keep track of context(s), with `pushws` and `popws` commands to manipulate the stack.
The `cd` command is an attempt to simplify the operation and will be subject to change.
When given:
- an object, cd will use that object as the new context by pushing it onto the workspace stack.
- "..", cd will leave the current context by popping the top workspace off the stack.
- no arguments, cd will move to the top workspace on the stack by popping off all workspaces.
Examples:
cd Foo
cd Foo.new
cd @ivar
cd ..
cd
```
https://github.com/ruby/irb/commit/4a0e0e89b7
values
(https://github.com/ruby/irb/pull/953)
Currently, users can only find out that they have set a wrong value
for IRB configs when the value is used, with opaque error messages like
"comparison of Integer with true failed (TypeError)".
This commit adds a new initialization step to validate the values of
some IRB configs, so that users can find out about the wrong values
during the initialization of IRB.
https://github.com/ruby/irb/commit/af8ef2948b
(https://github.com/ruby/irb/pull/948)
* Remove unnecessary code from command tests
* Improve help message for no meta commands
1. Add placeholder values for both command category and description
2. Update help command's output to give different types of categories
more explicit ordering
https://github.com/ruby/irb/commit/b1ef58aeff
commands
(https://github.com/ruby/irb/pull/944)
* Avoid raising errors while running help for custom commands
Raising an error from the help command is not a pleasure for the
end user, even if the command does not define any attributes
* Update test/irb/command/test_custom_command.rb
---------
https://github.com/ruby/irb/commit/c8bba9f8dc
Co-authored-by: Stan Lo <stan001212@gmail.com>
(https://github.com/ruby/irb/pull/934)
Since commands can't be chained with methods, their return values are
not intended to be used. But if IRB keeps storing command return values
as the last value, and print them, users may rely on such implicit
behaviour.
So to avoid such confusion, this commit suppresses command's
return values. It also updates some commands that currently rely on
this implicit behaviour.
https://github.com/ruby/irb/commit/fa96bea76f
as names
(https://github.com/ruby/irb/pull/932)
This will save users some heads scratching when they try to register a
command with a string name and found that it doesn't work.
I also rewrote converted custom command tests into integration tests to
make test setup/cleanup easier.
https://github.com/ruby/irb/commit/a91a212dbe
Some helpers, like Rails console's `app`, requires memoization of the
helper's ivars. To support it IRB needs to memoize helper method instances
as well.
https://github.com/ruby/irb/commit/169a9a2c30
(https://github.com/ruby/irb/pull/925)
This module was used to extend both commands and helpers when they're not
separated. Now that they are, and we have a Command module, we should move
command-related logic to the Command module and update related references.
This will make the code easier to understand and refactor in the future.
https://github.com/ruby/irb/commit/f74ec97236
debug_readline
(https://github.com/ruby/irb/pull/923)
* Remove exit and exti! command workaround when executed outside of IRB
Command was a method. It could be executed outside of IRB.
Workaround for it is no longer needed.
* Handle IRB_EXIT in debug mode
* Add exit and exit! command in rdbg mode
https://github.com/ruby/irb/commit/0b5dd6afd0
(https://github.com/ruby/irb/pull/922)
* Remove internal-only methods from Command::Base
Command#ruby_args and Command#unwrap_string_literal are used for default command's argument backward compatibility.
Moved these methods to another module to avoid being used from custom commands.
* Update lib/irb/command/edit.rb
---------
https://github.com/ruby/irb/commit/7405a841e8
Co-authored-by: Stan Lo <stan001212@gmail.com>
(https://github.com/ruby/irb/pull/886)
This is a feature that has been requested for a long time. It is now
possible to define custom commands in IRB.
Example usage:
```ruby
require "irb/command"
class HelloCommand < IRB::Command::Base
description "Prints hello world"
category "My commands"
help_message "It doesn't do more than printing hello world."
def execute
puts "Hello world"
end
end
IRB::Command.register(:hello, HelloCommand)
```
https://github.com/ruby/irb/commit/888643467c
(https://github.com/ruby/irb/pull/920)
This has a few benefits:
- We can keep hiding the evaluation logic inside the Context level, which
has always been the convention until #824 was merged recently.
- Although not an official API, gems like `debug` and `mission_control-jobs`
patch `Context#evaluate` to wrap their own logic around it. This implicit
contract was broken after #824, and this change restores it.
In addition to the refactor, I also converted some context-level evaluation
tests into integration tests, which are more robust and easier to maintain.
https://github.com/ruby/irb/commit/b32aee4068
(https://github.com/ruby/irb/pull/824)
* Command is not a method
* Fix command test
* Implement non-method command name completion
* Add test for ExtendCommandBundle.def_extend_command
* Add helper method install test
* Remove spaces in command input parse
* Remove command arg unquote in help command
* Simplify Statement and handle execution in IRB::Irb
* Tweak require, const name
* Always install CommandBundle module to main object
* Remove considering local variable in command or expression check
* Remove unused method, tweak
* Remove outdated comment for help command arg
Co-authored-by: Stan Lo <stan001212@gmail.com>
---------
https://github.com/ruby/irb/commit/8fb776e379
Co-authored-by: Stan Lo <stan001212@gmail.com>
(https://github.com/ruby/irb/pull/901)
* Always save irb_history in HOME or XDG_CONFIG_HOME
Also split irbrc search logic from irb_history search logic as a refactor
* Remove IRB.conf[:RC_NAME_GENERATOR] because it's not configurable
This conf is used to specify which irbrc to load. Need to configure before irbrc is loaded, so it's actually not configurable.
This conf is also used for history file search, but it is configurable by conf[:HISTORY_FILE].
* remove rc_file_test because it is tested with rc_files, remove useless test setup
* Make internal irbrc searching method private
https://github.com/ruby/irb/commit/11d03a6ff7
(https://github.com/ruby/irb/pull/897)
Some features of irb do not work properly when using the old rdoc.
I have compared several major versions and found that it works as intended from 4.0.0.
This problem occurs when there is a Gemfile.lock is installed with the old rdoc.
I don't know why this Gemfile.lock installs an older rdoc than the ruby bundled rdoc,
but specifying the version in the gemspec will at least prevent the problem.
NOTE: ruby/irb#704 problem does not occur with this change.
The following is test code.
```
### Usage: ruby __FILE__.rb
# # input RDoc and Tab
# >> RDoc<Tab>
#
### Expect: Display document of RDoc
### Actual: <internal:marshal>:34:in `load': instance of RDoc::Constant needs to have method `marshal_load' (TypeError)
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'irb'
# gem 'rdoc', '~> 4.0.0'
gem 'rdoc', '~> 3.12.0'
end
require 'rdoc'
require 'irb'
IRB.start
```
https://github.com/ruby/irb/commit/1a1fbba020
(https://github.com/ruby/irb/pull/888)
* Remove dead irb_level method
* Restructure workspace management
Currently, workspace is an attribute of IRB::Context in most use cases.
But when some workspace commands are used, like `pushws` or `popws`, a
workspace will be created and used along side with the original workspace
attribute.
This complexity is not necessary and will prevent us from expanding
multi-workspace support in the future.
So this commit introduces a @workspace_stack ivar to IRB::Context so IRB
can have a more natural way to manage workspaces.
* Fix pushws without args
* Always display workspace stack after related commands are used
https://github.com/ruby/irb/commit/61560b99b3
(https://github.com/ruby/irb/pull/882)
* Unroll extension method generation
Given we only have 2 remaining extension setter methods, both of which
only take 1 argument and don't have any alias, the current method generation
logic is overly complicated.
This commit simplifies the method generation logic by simply defining
the methods directly in the `IRB::Context` class.
* Fix use_loader extension
https://github.com/ruby/irb/commit/67eba5401b