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
📄
Blocks and enumerables
Run as I type
Reset
▶
Run
Ctrl
↵
RB
Ruby source code
words = "the quick brown fox jumps over the lazy dog".split # Enumerable is the whole point of Ruby collections. puts words.map(&:capitalize).join(" ") puts "#{words.size} words, #{words.sum(&:length)} letters" puts words.select { |w| w.length > 4 }.inspect puts words.partition { |w| w.length.even? }.inspect puts words.max_by(&:length) puts words.each_with_object(Hash.new(0)) { |w, h| h[w[0]] += 1 }.inspect # each_cons and each_slice look at neighbours and chunks. puts (1..6).each_cons(2).to_a.inspect puts (1..6).each_slice(2).to_a.inspect # A method that takes a block, and yields to it. def twice yield 1 yield 2 end twice { |n| puts "called with #{n}" }
Input
one line per
input()
call
Output
Rendered by your browser