feat: support Ruby hash literals and bracket access with dual-list storage#318
Merged
takaokouji merged 6 commits intodevelopfrom Mar 16, 2026
Merged
feat: support Ruby hash literals and bracket access with dual-list storage#318takaokouji merged 6 commits intodevelopfrom
takaokouji merged 6 commits intodevelopfrom
Conversation
Implement Ruby hash literal syntax ($a = {name: "Alice", age: 30})
using dual-list storage (_hash_<name>_keys_ + _hash_<name>_values_).
Supports symbol keys, string keys, hash rocket syntax, empty hashes,
and global/instance variable scopes.
Part of #315.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implement $a[:name] and $a["name"] hash bracket read using data_itemoflist(data_itemnumoflist(key, keys_list), values_list). Also pre-implements convertHashSet helper for Phase 3. Part of #315. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implement $a[:name] = "Bob" using delete+push pattern (4 blocks). Leverages Scratch index 0 = LIST_INVALID = no-op for if-less upsert. Supports both symbol and string keys. Part of #315. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
🚀 Preview deployed: https://smalruby.jp/smalruby3-editor/feature/ruby-hash-support/ |
…e 4) Hash literal, read, and write operations now throw descriptive errors when used in Ruby version 1. Added Japanese and hiragana locale strings. Part of #315. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…hase 5) Handle @ruby:lvar prefix in hash get/set comments for local variables. Generator now extracts variable name from lvar comment when present. Add locale messages and comprehensive roundtrip tests for all scenarios. Part of #315. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
constructor.name is mangled by terser in production builds, causing visitHashNode and visitKeywordHashNode to produce empty hash Maps. This fixes hash literal entries being lost in production. Part of #315. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
github-actions bot
pushed a commit
that referenced
this pull request
Mar 16, 2026
…hash-support feat: support Ruby hash literals and bracket access with dual-list storage
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
v2 限定で、Ruby ハッシュリテラルとブラケットアクセスを、既存の Scratch リスト2本(
_hash_<name>_keys_/_hash_<name>_values_)にマッピングして実現する。Closes #315
Implementation Steps
$a = {name: "Alice", age: 30}の converter + generator(TDD)$a[:name]/$a["name"]の converter + generator(TDD)$a[:name] = "Bob"の delete+push パターン converter + generator(TDD)Definition of Done
$a = {name: "Alice", age: 30}→ ブロック化 → Ruby 復元$a[:name]読み取りラウンドトリップ$a[:name] = "Bob"書き込み(既存キー更新)ラウンドトリップ$a[:new_key] = "value"書き込み(新規キー追加)ラウンドトリップ$a = {"foo" => "bar"}文字列キーのラウンドトリップ$a = {}空ハッシュのラウンドトリップ$a = {x: 10, y: 20}整数値ハッシュのラウンドトリップProduction Build Fix
visitHashNode/visitKeywordHashNodeでelement.constructor.name === 'AssocNode'を使用していたが、production build (esbuild minify) でクラス名がマングルされるためelement.toJSON().type === 'AssocNode'に修正。Test Coverage