Suppose, for the sake of argument, that we have a set of data that looks like this:
CODE:
people = {"Alice" => ["green", "alice@example.com"],
"Bob" => ["brown", "bob@example.com"]
}and we want to ignore eye colour and age and convert each element to a simple array containing name and email address. We might do this:
CODE:
people.map { |name, fields| [name, fields.last] }but it's not very clear what fields.last is. Ruby has some fairly powerful destructuring assignment, so we can reach inside the structure with parentheses to make things more explicit:CODE:
people.map { |name, (eye_color, email)| [name, email] }