Skip to content

feat: add arrayMethodWithBlock for block-accepting array methods#539

Merged
takaokouji merged 1 commit into
developfrom
feat/array-method-with-block
Apr 18, 2026
Merged

feat: add arrayMethodWithBlock for block-accepting array methods#539
takaokouji merged 1 commit into
developfrom
feat/array-method-with-block

Conversation

@takaokouji
Copy link
Copy Markdown

Summary

  • ブロック付きメソッド呼び出し用の汎用 C 形状ブロック smalrubyRuby_arrayMethodWithBlock を追加
  • 今回は each のみ実装。将来 tap, map, select 等を追加予定
  • BlockType.CONDITIONAL を使用(LOOP ではない — tap 等の非ループメソッドにも対応するため)

Block Design

配列 (ticket) . [each▼] do
  say("hello", 1)   ← SUBSTACK
end
  • RECEIVER: 値入力(String と同じパターン)
  • METHOD: ドロップダウン(現在 each のみ)
  • SUBSTACK: ブロック本体

Changes Made

VM (scratch-vm):

  • index.jsarrayMethodWithBlock ブロック定義 + 実行メソッド
  • block-definitions.jsarrayMethodWithBlockMenu メニュー追加
  • method-executors.jsexecuteArrayMethodWithBlock 実行ロジック
  • translations.json — ja/ja-Hira 翻訳追加

GUI (scratch-gui):

  • smalruby-ruby.js (converter) — each のコンバーター登録
  • smalruby-ruby.js (generator) — arrayMethodWithBlock ジェネレーター
  • smalruby-ruby.test.js — ラウンドトリップテスト追加

Test Plan

  • Array#each with block ラウンドトリップテスト pass
  • 既存テスト 23件 pass
  • lint pass (scratch-gui + scratch-vm)

Add a new C-shaped (CONDITIONAL) extension block
smalrubyRuby_arrayMethodWithBlock that handles array methods accepting
Ruby blocks, starting with `each`. This is a general-purpose block for
block-accepting methods (not each-specific), designed to also support
future methods like `tap`, `map`, `select`, etc.

The block uses BlockType.CONDITIONAL (not LOOP) because not all
block-accepting methods are loops (e.g., `tap` executes once).
Looping behavior is controlled in the execute function via
util.startBranch(1, true/false).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

@takaokouji takaokouji merged commit 4789f87 into develop Apr 18, 2026
9 checks passed
@takaokouji takaokouji deleted the feat/array-method-with-block branch April 18, 2026 17:57
github-actions Bot pushed a commit that referenced this pull request Apr 18, 2026
…thod-with-block

feat: add arrayMethodWithBlock for block-accepting array methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant