Commit 03933eb9

03933eb9bb2bMerged

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

Description

Add Symbol, String methods, Integer#to_s, boolean puts

New features:

  • Symbol literals (:hello) → C string constants
  • String#length/size → strlen()
  • String#upcase/downcase → sp_str_upcase/downcase (ctype.h)
  • String#include?(str) → strstr() != NULL
  • String + String → sp_str_concat (malloc'd)
  • Integer#to_s → sp_int_to_s (snprintf)
  • puts with Boolean → "true"/"false"

Test: examples/bm_strings.rb — all patterns, output matches Ruby. All regressions pass.

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

Details

Commit
03933eb9bb2b
Parent
f43f48b6b12f

examples/bm_strings.rbaddedView file

1+# Test Symbol and String methods
2+
3+# Symbol
4+s = :hello
5+puts s # hello
6+
7+# String methods
8+str = "Hello, World!"
9+puts str.length # 13
10+puts str.upcase # HELLO, WORLD!
11+puts str.downcase # hello, world!
12+puts str.include?("World") # true
13+puts str.include?("xyz") # false
14+
15+# String concatenation
16+a = "foo"
17+b = "bar"
18+c = a + b
19+puts c # foobar
20+
21+# to_s on integers
22+n = 42
23+puts n.to_s # 42