Ruby 2.3 added to_proc

Photo by Émile Perron on Unsplash

Hash#to_proc returns a proc that takes a key a parameter and returns the matching value.

a = {
  name: "Catalin",
  email: "cionescu@test.com",
  title: "Software Engineer"}

[:name, :title].map(&a) # => [ "Catalin", "Software Engineer" ]

Same as Hash#slice, just using procs.

NOTE: Hash#slice will be added to Ruby 2.5