Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

ruby zip rows and columns

columns = [ "Name", "city", "employed"]
 
rows = [ 
  [ "Matt",   "Seattle",    true ], 
  [ "Amy",  "Chicago", true], 
  [ "Nice", "Lahore",     false ]
]

rows.map{|r| Hash[ columns.zip(r) ] }
# [
#	{"Name"=>"Matt", "city"=>"Seattle", "employed"=>true}, 
#	{"Name"=>"Amy", "city"=>"Chicago", "employed"=>true}, 
#	{"Name"=>"Nice", "city"=>"Lahore", "employed"=>false}
# ]
 
PREVIOUS NEXT
Tagged: #ruby #zip #rows #columns
ADD COMMENT
Topic
Name
7+1 =