# A guided tour of Ruby (mruby) running on calog.
# Demonstrates: a Range, reduce with a block, select with a symbol-to-proc, a Hash, then the
# jsonStringify/jsonParse and cryptoHashSha256 natives. Ruby's puts works; real file/socket IO
# is provided by calog's fs*/net* natives (not Ruby's stdlib) -- so scripts stay uniform.
# run: bin/calog examples/scripts/languages/ruby.rb

nums  = (1..5).to_a
total = nums.reduce(0) { |acc, n| acc + n }
evens = nums.select(&:even?)
puts "nums=#{nums.inspect} total=#{total} evens=#{evens.inspect}"

user = { "name" => "ada", "age" => 36 }
calogPrint("user as JSON:", jsonStringify(user))

parsed = jsonParse('{"lang":"ruby","ints":[1,2,3]}')
calogPrint("parsed lang:", parsed["lang"], "| first int:", parsed["ints"][0])
calogPrint("sha256(calog):", cryptoHashSha256("calog"))

calogExit(0)
