Commit 5f40630d

5f40630dc111Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · +1 added · ~1 modified

Description

Add Struct.new support

Struct.new(:x, :y) detected in class analysis → synthetic class:

  • Fields from symbol arguments → ivars with getter/setter
  • Synthetic initialize assigns params to fields
  • Works with all existing features (method calls, puts, etc.)

Test: examples/bm_struct.rb — Point and Color structs. Output matches Ruby.

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
5f40630dc111
Parent
41023eb2c21a

examples/bm_struct.rbaddedView file

1+# Test Struct
2+
3+Point = Struct.new(:x, :y)
4+
5+p1 = Point.new(3, 4)
6+puts p1.x # 3
7+puts p1.y # 4
8+
9+p1.x = 10
10+puts p1.x # 10
11+
12+# Struct with methods
13+Color = Struct.new(:r, :g, :b)
14+
15+c = Color.new(255, 128, 0)
16+puts c.r # 255
17+puts c.g # 128
18+puts c.b # 0