-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support Ruby 3.4.x #1935
support Ruby 3.4.x #1935
Conversation
This reverts commit 177fd3b.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
たすかります!!
EnforcedStyle: never | ||
Enabled: true | ||
Exclude: | ||
- 'samples/**/*' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
samples以下のマジコメはどうでもいいっしょ…ということで放置しています
res = '' | ||
res = +'' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一部破壊的に文字列を使っているところでは、最初の初期化時に+
をつけてmutableにしています
@package_attrs << %Q( prefix="#{prefixes_str}") | ||
@package_attrs = %Q( prefix="#{prefixes_str}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
再代入は問題ない(既存文字列を破壊するわけではないため)ので、初期化直後に破壊的追加を行っている箇所については再代入に変更しているところもあります
title = ReVIEW::I18n.t('part', part.number) | ||
title = +ReVIEW::I18n.t('part', part.number) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+''
等ではなく、既存のimmutableな文字列をmutableにするために+
を追加しているところもあります
texsrc = default_imgmath_preamble | ||
if @config['imgmath_options']['preamble_file'] && File.readable?(@config['imgmath_options']['preamble_file']) | ||
texsrc = File.read(@config['imgmath_options']['preamble_file']) | ||
end | ||
texsrc_pre = | ||
if @config['imgmath_options']['preamble_file'] && File.readable?(@config['imgmath_options']['preamble_file']) | ||
File.read(@config['imgmath_options']['preamble_file']) | ||
else | ||
default_imgmath_preamble | ||
end | ||
|
||
texsrc << <<-EOB | ||
texsrc = <<-EOB | ||
#{texsrc_pre} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
新しい文字列を作る際に、既存のimmutableな文字列を埋め込むことはできるので、破壊的追加を行っていたところに別の(immutableな)文字列用変数を追加しているところもあります
str << "-#{@counter[i]}" | ||
str = "#{str}-#{@counter[i]}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これも破壊的追加の代わりに、immutableな文字列を埋め込んで都度新しいimmutableな文字列を作ることで回避したものです。
基本的に<<
は全部この手の変更で置き換えられそうですが、それはそれで面倒かつコードが読みやすくならなさそうなので、この書き方はたまにしか使ってません。
prefix = if @chapter.is_a?(ReVIEW::Book::Part) | ||
I18n.t('part_short', @chapter.number) | ||
else | ||
@chapter.format_number(false) | ||
end | ||
prefix = [] | ||
prefix << if @chapter.is_a?(ReVIEW::Book::Part) | ||
I18n.t('part_short', @chapter.number) | ||
else | ||
@chapter.format_number(false) | ||
end | ||
0.upto(level - 2) { |i| prefix << ".#{@counter[i]}" } | ||
prefix << I18n.t('chapter_postfix') | ||
prefix | ||
prefix.join |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「文字列はimmutableだけど配列は別にimmutableにならない」かつ「<<
は文字列にも配列にも使える」というのを利用して、<<
はそのままにしつつ最初の初期化時に文字列から配列に変更し、最後に.join
して文字列化する、というのも使っています
@log_io.string = '' | ||
@log_io.rewind | ||
@log_io.truncate(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これは+''
でも良かったのですが、毎回新しい文字列オブジェクトを作るのはあんまり効率良くないよな…と思い返して、文字列は再利用する形でカーソルを先頭に戻す+既存のデータを初期化するように変更しています。
まあテストなので落ちてなければ大丈夫かな…というくらいの温度感です。
assert_match(/SUCCESS/, e) | ||
assert_match(/SUCCESS|INFO/, e) # XXX TTY::Logger should be fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これはTTY::Loggerの問題のせいなので、そちらが直るまではいったんこれでしのごうかと思っています。
li = LineInput.new(io) | ||
li = ReVIEW::LineInput.new(io) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これは単独のテストで動かすと落ちるようだったので修正しています(まあ確かに落ちるというか、クラス名ちゃんと指定するべきだよね…とは思いました)。
data = '' | ||
li.each { |l| data << l } | ||
assert_equal content, data | ||
data = [] | ||
li.each { |l| data << l } # rubocop:disable Style/MapIntoArray | ||
assert_equal content, data.join |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これも文字列から配列に変えたものです。
rubocopが「eachは使わない方が…」とか言ってくるのですが、こっちはeachのテストをするために使っているのでコメントで抑止しています。
assert_match(/undefined local variable or method `not_existed_method'/, error_msg) | ||
assert_match(/undefined local variable or method ('|`)not_existed_method'/, error_msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これはRuby 3.4でエラーメッセージのフォーマットが変わったやつへの対応です。
以前のRubyでも動くようにどっちでも許すようにしています。
主な変更点については一通りコメントしておきました |
TTY::Loggerは動きがないので、このPRでマージしておきますね |
Ruby 3.4対応です。
素直に対応するでもあんまり変わらないかも? ということでもろもろ対応中です。
関連