Skip to content
Justice Tech School

Method Chaining and Symbols to Proc

Chain methods and use &:method as a shortcut for a block.

Example
words = %w[apple Banana cherry]
puts words.map(&:downcase).select { |w| w.length > 5 }.sort.join(", ")
puts (1..10).select(&:even?).map { |n| n * n }.sum

Result

banana, cherry
220

Exercise

Shortcut block.

map(&:)

Quiz Test

What does &:upcase mean?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.