Playground · Methods and traits · 28 of 33
strings
Strings, and to_s: how a type says what it looks like.
# Strings, and `to_s`: how a type says what it looks like. s = "Hello, iyi" puts s.size puts s.upcase puts s.downcase puts s.includes?("iyi") puts s + "!" puts s.split(' ') # Interpolation calls `to_s` on whatever is inside `#{}`. puts "#{1 + 1} and #{true} and #{[1, 2]}" # Give your own type a `to_s`, and it prints the way you say. struct Money def initialize(@lira : Int32, @kurus : Int32) end def to_s : String "#{@lira},#{@kurus.to_s.rjust(2, '0')} TL" end end price = Money.new(12, 5) puts price.to_s puts "total: #{price}" # Padding lines up columns. puts "item".ljust(8) + "12" puts "total".ljust(8) + "99"
Press Run.
The pane no longer holds samples/tour/strings.iyi. Run executes strings.wasm, the module the compiler built from the recorded file, so your edit is not in this run: there is no iyi compiler in this page. How this works
recorded with iyi 0.18.0 (built on Crystal 1.22.0-dev [2a9653052] (2026-10-18)) · Linux 7.0.0-38-generic x86_64, QEMU Virtual CPU version 2.5+ · 2026-10-19
You can type in the pane: nothing here compiles, so what you type cannot run, and the page says which bytes it is running the moment the text stops being the recorded file. There is no standard input, no filesystem and no threads on this target, and one sample fails on purpose for exactly that reason.
Run executes strings.wasm, the module the compiler built from this file, in your browser. How this works
Try it on your machine
Copy the program into strings.iyi, change something, and run it. Only a compiler on your own machine can run what you wrote.
$ iyi run strings.iyi