Commit 89af6d86
89af6d86680dMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · +1 added · ~1 modified
Description
Add File.read/write/exist?/delete, fix puts trailing newline
File I/O via C stdio:
- File.read(path) → fopen/fread/fclose
- File.write(path, data) → fopen/fwrite/fclose
- File.exist?(path) → fopen check
- File.delete(path) → remove()
Fix: puts with STRING now matches Ruby behavior — doesn't add newline if string already ends with one.
Category 4 (built-in classes) — File basics done.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 89af6d86680d
- Parent
- 0fa8b5922e38
examples/bm_fileio.rbaddedView file
1+
# Test basic File I/O2+
3+
# Write a file4+
File.write("/tmp/spinel_test.txt", "Hello from Spinel!\nLine 2\n")5+
6+
# Read the file7+
content = File.read("/tmp/spinel_test.txt")8+
puts content9+
10+
# File.exist?11+
puts File.exist?("/tmp/spinel_test.txt") # true12+
puts File.exist?("/tmp/nonexistent.txt") # false13+
14+
# Clean up15+
File.delete("/tmp/spinel_test.txt")16+
puts File.exist?("/tmp/spinel_test.txt") # false17+
18+
puts "done"src/codegen.cmodifiedView file
Loading diff…