Group programming languages by their first letter
langs = %w[ java perl python ruby ] groups = langs.group_by {|lang| lang[0] } p groups # => {"j"=>["java"], "p"=>["perl", "python"], "r"=>["ruby"]}