feat: support attr_accessor/attr_reader/attr_writer in class definitions#546
Merged
Conversation
Converter: - Pre-scan class body for attr_accessor/reader/writer calls - Extract symbol names from SymbolNode.unescaped.value - Store accessor info in context and @ruby:class comment - Resolve getter (foo, self.foo) → @foo variable read - Resolve setter (self.foo = val) → @foo variable assignment Generator: - Parse attr info from @ruby:class comment in init() (before code gen) - data_variable: output accessor name without @ prefix - data_setvariableto: output self.name = val for accessor writes - _generateInitialize: skip accessor variables - wrapClassCode: output attr_accessor/reader/writer lines Closes #545 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
🚀 Preview deployed: https://smalruby.jp/smalruby3-editor/feat/attr-accessor/ |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
github-actions Bot
pushed a commit
that referenced
this pull request
Apr 19, 2026
…essor feat: support attr_accessor/attr_reader/attr_writer in class definitions
This was referenced Apr 19, 2026
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
attr_accessor、attr_reader、attr_writerをクラス定義内でサポートfoo,self.foo) →@foo変数参照に変換self.foo = val) →@foo = val変数代入に変換@ruby:classコメントに attr 情報を保存)変換例
Changes Made
Converter:
class-visitor.js—attr_accessor/reader/writerのプレスキャン、フィルタリング、コメントマーカーexpressions.js— getter/setter 解決(AST のSelfNode判定で_getNodeTypeName使用)Generator:
index.js—init()で@ruby:classコメントから attr 名を早期解析data.js—data_variable: accessor 名は@なしで出力、data_setvariableto:self.name = valで出力class-wrapper.js—attr_accessor :hp行の出力、def initializeから accessor 変数を除外Test Plan
Closes #545