---
# System prepended metadata

title: '[Ruby On Rails]用map將Hash資料填入陣列'
tags: [Ruby On Rails]

---

# [Ruby On Rails]用map將Hash資料填入陣列

###### tags: `Ruby On Rails`

參考資料:
https://progressbar.tw/courses/3/watching
https://railsbook.tw/chapters/06-ruby-basic-2.html


```ruby!
products=[*1..3].map{
  |k| {
    id:k,
    name:"巧克力#{k}",
  }
}

p products
#[{:id=>1, :name=>"巧克力1"}, {:id=>2, :name=>"巧克力2"}, {:id=>3, :name=>"巧克力3"}]

```

