Skip to content

refactor: rename stringMethodR/C to methodR/C and add collection methods (#524 Phase1)#526

Merged
takaokouji merged 3 commits into
developfrom
feat/tryruby-method-r-refactor
Apr 18, 2026
Merged

refactor: rename stringMethodR/C to methodR/C and add collection methods (#524 Phase1)#526
takaokouji merged 3 commits into
developfrom
feat/tryruby-method-r-refactor

Conversation

@takaokouji
Copy link
Copy Markdown

Summary

  • smalrubyRuby_stringMethodRsmalrubyRuby_methodR にリネーム(文字列以外のレシーバーにも対応)
  • smalrubyRuby_stringMethodCsmalrubyRuby_methodC にリネーム
  • 新 REPORTER メソッド追加: lines, max, sort, join, keys, values
  • 新 COMMAND メソッド追加: sort!, reverse!
  • プロジェクト読み込み時の自動マイグレーション(旧 opcode → 新 opcode、問答無用)

Changes

VM (scratch-vm)

  • src/extensions/smalruby_ruby/index.js — opcode リネーム + 新メソッドの argumentsByMethod・メニュー・実行ロジック追加
  • src/extensions/smalruby_ruby/translations.json — 翻訳キーを methodR/methodC に更新
  • src/serialization/smalruby-migration.jsmigrateStringMethodBlocks() 追加
  • src/virtual-machine.jsloadProject で常にマイグレーション実行

GUI (scratch-gui)

  • src/lib/ruby-to-blocks-converter/smalruby-ruby.js — opcode リネーム + 新メソッドのコンバーター登録
  • src/lib/ruby-generator/smalruby-ruby.js — opcode リネーム + COMMAND の引数なし対応

Tests

  • コンバーター: 既存テスト opcode 更新 + 新メソッド 7 テスト追加
  • ジェネレーター: opcode 更新 + sort! テスト追加
  • マイグレーション: migrateStringMethodBlocks テスト追加

TryRuby 対応状況

この PR で以下のレッスンが新たにブロック変換可能になる見込み:

  • L130: [12,47,35].max.max
  • L160: ticket.sort!.sort!
  • L210: poem.lines.lines
  • L210: poem.lines.reverse.lines + .reverse チェーン
  • L220: poem.lines.reverse.join.lines + .reverse + .join チェーン
  • L270: books.keys.keys

Related Issues

Refs #524 (Phase 1 #4-#9)

Rename smalrubyRuby_stringMethodR → smalrubyRuby_methodR and
smalrubyRuby_stringMethodC → smalrubyRuby_methodC to support
methods on all receiver types (string, array, hash).

New REPORTER methods: lines, max, sort, join, keys, values
New COMMAND methods: sort!, reverse!

Add automatic migration for old project files (stringMethodR/C
opcodes are replaced with methodR/C on load, unconditionally).

Refs #524 (Phase 1 #4-#9)

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

takaokouji and others added 2 commits April 17, 2026 21:25
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Convert list variable receivers to data_listcontents so the VM
  receives actual list contents (not empty scalar variable value)
- Hash#keys/values reference the correct sub-list (__hash_X_keys__
  / __hash_X_values__)
- VM methodR: implement actual array operations (max finds maximum,
  sort sorts numerically, join concatenates with separator, lines
  splits by newline)

Verified all 10 methods produce correct runtime output:
  reverse→"ymmiJ", delete→"heo", gsub→"herro",
  max→"47", sort→"12 35 47", join(", ")→"12, 47, 35",
  keys→"Ruby", values→"good", lines→"hello\n world\n"

Refs #524

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@takaokouji takaokouji merged commit a563e75 into develop Apr 18, 2026
9 checks passed
@takaokouji takaokouji deleted the feat/tryruby-method-r-refactor branch April 18, 2026 01:23
github-actions Bot pushed a commit that referenced this pull request Apr 18, 2026
…method-r-refactor

refactor: rename stringMethodR/C to methodR/C and add collection methods (#524 Phase1)
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