[ruby/irb] Suppress "literal string will be frozen in the future"

warning
(https://github.com/ruby/irb/pull/1019)

* Suppress "literal string will be frozen in the future" warning

Before change:

```console
$ ruby -W -I lib -e 'require "irb"; IRB.setup(nil); IRB::Irb.new.build_statement("1 + 2")'
/Users/zzz/src/github.com/ruby/irb/lib/irb.rb:1135: warning: literal string will be frozen in the future
```

After change:

```console
$ ruby -W -I lib -e 'require "irb"; IRB.setup(nil); IRB::Irb.new.build_statement("1 + 2")'
```

* Making build_statement not modify the given argument

Because improves readability and code quality.

Co-authored-by: tomoya ishida <tomoyapenguin@gmail.com>

---------

https://github.com/ruby/irb/commit/3da04b9786

Co-authored-by: tomoya ishida <tomoyapenguin@gmail.com>
This commit is contained in:
Tsutomu Katsube 2024-10-19 02:15:22 +09:00 committed by git
parent 09ddfd4d1c
commit f370a31578

View File

@ -1132,7 +1132,7 @@ module IRB
return Statement::EmptyInput.new
end
code.force_encoding(@context.io.encoding)
code = code.dup.force_encoding(@context.io.encoding)
if (command, arg = @context.parse_command(code))
command_class = Command.load_command(command)
Statement::Command.new(code, command_class, arg)