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_init
2+
3+Session = Struct.new(
4+ :pid, :name, :status,
5+ keyword_init: true
6+)
7+
8+s = Session.new(pid: 123, name: "test", status: "running")
9+puts s.pid # 123
10+puts s.name # test
11+puts s.status # running
12+
13+s.status = "done"
14+puts s.status # done
15+
16+puts "done"