Skip to content
Omni Academy
Search courses and lessons
Search
Courses
Backend Development
9
Databases
1
Frontend Development
5
Data Science
5
All courses →
Playground
HTML & CSS
JavaScript
TypeScript
Python
PHP
Ruby
Light
Dark
Auto
Sign in
Get started
All
Backend Development
Databases
Frontend Development
Data Science
Playground
Blog
HTML
JS
TS
PY
PHP
RB
← Courses
📄
Ruby basics
Run as I type
Reset
▶
Run
Ctrl
↵
RB
Ruby source code
# Real CRuby compiled to WebAssembly. It runs in this tab, not on a # server, so nothing you type here leaves your browser. Learner = Struct.new(:name, :score, :level) learners = [ Learner.new("Aisha", 92, :advanced), Learner.new("Kenji", 78, :intermediate), Learner.new("Lena", 85, :expert), ] # Blocks read like the sentence they are. passing = learners.select { |l| l.score >= 80 } puts "Passing: #{passing.map(&:name).join(', ')}" average = learners.sum(&:score) / learners.size.to_f puts format("Average: %.1f", average) # group_by and tally do the counting you would otherwise write by hand. puts learners.group_by { |l| l.score >= 80 }.transform_keys { |k| k ? :pass : :fail } .transform_values(&:size) .inspect puts (1..5).map { |n| n**2 }.inspect
Input
one line per
input()
call
Output
Rendered by your browser