Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save harrisonmalone/e41010deba93e3a9920335d9969f5043 to your computer and use it in GitHub Desktop.
Save harrisonmalone/e41010deba93e3a9920335d9969f5043 to your computer and use it in GitHub Desktop.
# the main difference between `.each` and `.map`
# they both iterate through a block but if you want to store an edited array or hash you need to use map
# if you simply want to display text by using `puts` on the block arguments then `each` is more useful
furniture = [
{"name" => "bed", "color" => "black", "size" => "12", "date_created" => "12/6", "condition" => "New"},
{"name" => "chair", "color" => "brown", "size" => "7", "date_created" => "6/13", "condition" => "Used"},
{"name" => "desk", "color" => "maple", "size" => "9", "date_created" => "2/13", "condition" => "New"}
]
x = furniture.map do |x|
x.values
end
p x
x = furniture.each do |x|
p x.values
end
p x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment