Skip to content

Instantly share code, notes, and snippets.

@jmoon90
Created November 18, 2013 19:46
Show Gist options
  • Select an option

  • Save jmoon90/7534149 to your computer and use it in GitHub Desktop.

Select an option

Save jmoon90/7534149 to your computer and use it in GitHub Desktop.
#array to hash
require "pry"
salutations = [
'Mr.',
'Mrs.',
'Mr.',
'Dr.',
'Ms.'
]
first_names = [
'John',
'Jane',
'Sam',
'Louise',
'Kyle'
]
last_names = [
'Dillinger',
'Cook',
'Livingston',
'Levinger',
'Merlotte'
]
addresses = [
'33 Foolish Lane, Boston MA 02210',
'45 Cottage Way, Dartmouth, MA 02342',
"54 Sally\'s Court, Bridgewater, MA 02324",
'4534 Broadway, Boston, MA 02110',
'4231 Cynthia Drive, Raynham, MA 02767'
]
i = 0
while i <= 4
array_of_hash = [
{
salutation: "#{salutations[i]}", first_name: "#{first_names[i]}",
last_name: "#{last_names[i]}", address: "#{addresses[i]}"
}#
]
i += 1
array_of_hash.each do |hash|
print hash[:salutation] + " "
print hash[:first_name] + " "
puts hash[:last_name]
puts hash[:address]
puts
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment