Repository navigation
fix(ruby): keep warp and digit-leading names of custom blocks in ruby - #2123
Merged
smalruby3-editor-bot[bot] merged 2 commits intoNov 17, 2026
Merged
Conversation
"Run without screen refresh" of a custom block is written `without_screen_refresh def foo ... end`. The parse stage unwraps the call to the def and remembers it, so my-blocks.js sets warp "true"; before, Ruby dropped it and converting back turned it off. A custom block name that starts with a digit or is a reserved word gets `_` in front (`1 文字えらぶ` -> `def _1_文字えらぶ`; one digit gets `__`, as `_1`..`_9` are numbered parameters), and the converter takes it off again (ruby-method-name.js). The @ruby:return markers are read with [^:,\s]+ instead of \w+, which missed Japanese method names. The smalruby3 gem gets a no-op `without_screen_refresh` class method. Closes #2114 Closes #2116 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
🚀 Preview deployed (stg API): https://preview.smalruby.app/fix-converter-procedure-warp-name-8f52ad7a/ |
smalruby3-editor-bot
Bot
deleted the
fix/converter-procedure-warp-name
branch
November 17, 2026 07:37
smalruby3-editor-bot Bot
added a commit
that referenced
this pull request
Nov 17, 2026
…103b chore: merge develop into topic/lessons-lm (#2123)
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
定義ブロック(ブロックを作る)の Ruby での表し方の 2 つの不具合を直す。どちらも
defの行と生成器procedure.js/ 変換器my-blocks.jsの同じ所を変えるので、1 つの PR にした。#2114 「画面を再描画せずに実行する」が Ruby を通すと消える
defの前にwithout_screen_refreshを書く形にした(Ruby のprivate def fooと同じ形。Ruby だけで書く人も書ける)。変換器は解析の段で、この呼び出しを中の
defに置きかえて(screen-refresh-defs.js)、そのdefを覚える。分析・class / module・コメント・ブロック内defの検査などは今までどおりのdefとして見るので、ほかの所を変えずにすむ。my-blocks.jsがwarpを"true"にする(呼び出しのmutation.warpも合わせる)。生成器はmutation.warpが"true"/trueのとき前に付ける。class の中・module(include)・v1(def self.)も往復する。自分でdef without_screen_refreshを定義したコードでは置きかえない。smalruby3 gem には、名前を返すだけのクラスメソッド
without_screen_refreshを足した(生成した Ruby が gem でNoMethodErrorにならないように。gem の側で warp の動きはまだ実装していない)。#2116 名前が数字で始まる定義ブロックが
def 1_文字えらぶになるメソッドにできない名前は前に
_を付け、変換器が取る(src/lib/ruby-method-name.jsに 1 か所)。end・ifなど)。__を付ける(_1〜_9は Ruby の番号指定パラメータで名前にできない。「1」→__1)。_で始まる同じ形の名前(「_1x」「_end」)は、もう 1 つ_を付けるので(__1x)、どの名前も往復で変わらない。_fooのような名前は今までどおり。同じところで見つけて直したもの
@ruby:return:<メソッド>を\w+で読んでいたため、日本語の名前のメソッドでreturnを使う/同じ行で 2 回呼ぶと、@_return_…_ = ""と控えの行が Ruby に出ていた。[^:,\s]+で読むようにした(data.js/procedure.js/control.jsの 5 か所)。class-wrapper.jsのファイル書き出しで、ハット/defの節を見分ける正規表現にwithout_screen_refresh defを足した。Test Coverage
test/unit/lib/ruby-roundtrip/my-block-warp-and-name.test.js(24 件: warp の変換・生成・真偽値の warp・引数と戻り値・2 つの定義・v1・class・module・自分で定義したwithout_screen_refresh、名前1 文字えらぶ・end・if・_1 x・_end・1・_1・10の往復、戻り値・明示のreturn・warp つきの往復)。修正前に 17 件が落ちることを確認。ruby/smalruby3/test/dsl_test.rbに 1 件(コンテナに Ruby が無いので手元では流していない。CI の ci-ruby で確かめる)。class・class-error-message・method-return1〜5・module・my-blocks1〜3・my-blocks-backward-compat・super・visibility-modifiers、generator のclass-wrapper・class・method-return・module・control1/2、module-sync、ruby-roundtrip-class-*(4)・ruby-roundtrip-method-return、roundtrip のmy_blocks・case-procedure-call・return-value-used-twice・method-return-value-shapes・return-literal-no-orphan・return-call-paren-list-and-self-line。src/lib/ruby-method-name.jsは.prettierignoreに追加。Docs
docs/ruby-editor/bridging-patterns.md: P20「定義ブロックの名前と『画面を再描画せずに実行する』」を追加、「変換器が使う名前」に_<名前>を追加。without_screen_refresh defと名前の_の決まりを追記。見つけたほかの点(この PR では直していない)
_になり、ブロックに戻しても_のまま(「1 文字えらぶ」→「1_文字えらぶ」。前からの動き)。-など Ruby の名前に使えない記号の入った定義ブロックの名前は、そのまま書くので文法エラーになる。def bar(n); say(foo(n)); end; bar(3)が「My Block "bar" の引数の型がまちがっています」になる(warp と関係なく、develop でも起きる)。without_screen_refresh defの行を読めない。without_screen_refreshにふりがなを付けない(with_screen_refreshも付けていない)。Closes #2114
Closes #2116
🤖 Generated with Claude Code