With verbopse mode (-w), the interpreter shows a warning if
a block is passed to a method which does not use the given block.
Warning on:
* the invoked method is written in C
* the invoked method is not `initialize`
* not invoked with `super`
* the first time on the call-site with the invoked method
(`obj.foo{}` will be warned once if `foo` is same method)
[Feature #15554]
`Primitive.attr! :use_block` is introduced to declare that primitive
functions (written in C) will use passed block.
For minitest, test needs some tweak, so use
ea9caafc07
for `test-bundled-gems`.
(https://github.com/ruby/reline/pull/649)
* Fix waiting_proc precedence
* Fix waiting_operator bugs
* Add waiting_proc and vi_waiting_operator test
* Fix vi waiting operator arg number
vi_arg and vi_waiting_operator_arg should be multiplied
* Implement `yy` copies whole line in vi_command mode
* Simplify incremental search cancel test
* Add complex vi test with waiting_proc and vi_waiting_operator, split test input
https://github.com/ruby/reline/commit/777dffae1c
(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
navigation
(https://github.com/ruby/reline/pull/677)
Fixes https://github.com/ruby/reline/pull/675
This commit extracts the upward navigation condition in `LineEditor#input_key` to a new private method, and adds a new alias. This change allows Reline to support upward navigation in when a user has configured `inputrc` to map Shift-Tab to `menu-complete-backward`, a common setting in Bash (>= 4.x).
Instead of special-casing upward navigation in `LineEditor#input_key`, we now allow it to be processed by the branch that calls `process_key`. The extracted method no longer includes the editing mode check since this check is already made by `#wrap_method_call` by the time `#completion_journey_up` (or `#menu_complete_backward`) is called. Since upward navigation is happening in a method other than `#input_key` now, the `completion_occurs` variable that used to be local to `#input_key` is changed to an instance variable so that the new method can change its value. (I see many examples of mutating such instance variables in `LineEditor`, so I assumed this would be an uncontroversial change consistent with the coding practices already in place.)
Test coverage of this change has been added to the emacs and vi `KeyActor` tests.
Many thanks to @ima1zumi for their very helpful comments on #675 which encouraged me to contribute this work!
https://github.com/ruby/reline/commit/2ccdb374a4
Given this example:
```rb
<<~HEREDOC
#{x}
HEREDOC
```
Both the parser gem and Prism's translation layer would generate the following AST:
```
s(:dstr,
s(:begin,
s(:int, 1)),
s(:str, " a\n"))
```
However, the parser gem inserts a empty string node into this node's location, like:
```
<Parser::Source::Map::Heredoc:0x0000000104ce73b8
@expression=#<Parser::Source::Range (string) 0...10>,
@heredoc_body=#<Parser::Source::Range (string) 11...20>,
@heredoc_end=#<Parser::Source::Range (string) 20...27>,
@node=s(:dstr,
s(:str, ""),
s(:begin,
s(:int, 1)),
s(:str, " a\n"))>
```
This is required to calculate the correct whitespace for the heredoc body.
We need to adjust the translation layer to account for this.
With this fix, we also won't need to ignore the tilde heredoc fixture anymore.
https://github.com/ruby/prism/commit/e7372e3ba5
(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>
This patch fixes an error when a default gem that will be migrated to
a bundled gem is loaded from `-r` option.
Problem
===
`bundle exec ruby -rostruct -e ''` unexpectedly raises the following error:
```console
$ ruby -v
ruby 3.4.0dev (2024-04-08T02:39:00Z master 6f7e8e278f) [arm64-darwin21]
$ bundle init && bundle install
$ bundle exec ruby -rostruct -e ''
/Users/kuwabara.masataka/.rbenv/versions/trunk/lib/ruby/3.4.0+0/bundled_gems.rb:111:in 'Gem::BUNDLED_GEMS.warning?': undefined method 'find' for nil (NoMethodError)
caller = caller_locations(3, 3).find {|c| c&.absolute_path}
^^^^^
from /Users/kuwabara.masataka/.rbenv/versions/trunk/lib/ruby/3.4.0+0/bundled_gems.rb:75:in 'block (2 levels) in Kernel#replace_require'
```
Solution
===
This patch uses a safe navigation operator to fix this problem. By this
change, the command will show the warning message correctly.
```console
$ bundle exec ruby -rostruct -e ''
warning: ostruct was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.5.0. Add ostruct to your Gemfile or gemspec.
```
(https://github.com/ruby/irb/pull/916)
handle_exception now applies the filter_backtrace to exception
backtraces prior to formatting the lines with Exception#full_message
This fixes a bug in upstream projects, notably Rails, where the
backtrace filtering logic expects the lines to be formatted as
Exception#backtrace.
https://github.com/ruby/irb/commit/805ee008f9
Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Introduce a new mkmf option `--target-rbconfig` to specify the RbConfig
file for the deployment target platform. This option is useful for
cross-compiling Ruby extensions without faking the global top-level
`RbConfig` constant.