iyi

Playground · Data · 19 of 33

hashes

Hashes: keys to values, in insertion order.

samples/tour/hashes.iyi · hashes.wasm · 160 KB
# Hashes: keys to values, in insertion order.

ages = {"Ayşe" => 31, "Mehmet" => 27}
puts ages["Ayşe"]
puts ages.size

ages["Zeynep"] = 40
puts ages.keys

# `[]?` answers nil for a missing key instead of failing.
puts ages["Ali"]?
puts ages.has_key?("Ali")

ages.each do |name, age|
  puts "#{name} is #{age}"
end

# An empty hash needs both types written down.
counts = {} of String => Int32
["a", "b", "a"].each do |letter|
  counts[letter] = (counts[letter]? || 0) + 1
end
puts counts
output
Press Run.

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 hashes.wasm, the module the compiler built from this file, in your browser. How this works

Try it on your machine

Copy the program into hashes.iyi, change something, and run it. Only a compiler on your own machine can run what you wrote.

sh, after installing
$ iyi run hashes.iyi