Commit dd1885ef
dd1885efd253Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · +1 added · ~1 modified
Description
Add Struct keyword_init: true support
Struct.new(:pid, :name, :status, keyword_init: true) now generates constructors that accept keyword arguments. Call sites like Session.new(pid: 123, name: "test") correctly unpack the KeywordHashNode and reorder args by field position. Type inference also handles keyword_init by matching keyword arg names to params.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- dd1885efd253
- Parent
- 72f58ec17629
examples/bm_struct_kw.rbaddedView file
1+
# Test Struct with keyword_init2+
3+
Session = Struct.new(4+
:pid, :name, :status,5+
keyword_init: true6+
)7+
8+
s = Session.new(pid: 123, name: "test", status: "running")9+
puts s.pid # 12310+
puts s.name # test11+
puts s.status # running12+
13+
s.status = "done"14+
puts s.status # done15+
16+
puts "done"src/codegen.cmodifiedView file
Loading diff…