JT Archie

# Ruby Syntax Sugar: Ampersand Operator

Ruby has syntax sugar that can help write more readable code, once you understand it.

For example, given a list of words, lets have them all lowercase.

words = ['Tea Cup', 'AmAzIng'].map do |word|
  word.downcase
end

We can use syntax sugar to avoid the boiler plate.

The ampersand says, call the downcase method on each value.

words = ['Tea Cup', 'AmAzIng'].map(&:downcase)

# Follow for more tips