Skip to content

Instantly share code, notes, and snippets.

@igaiga
Created May 24, 2012 13:55
Show Gist options
  • Save igaiga/2781674 to your computer and use it in GitHub Desktop.
Save igaiga/2781674 to your computer and use it in GitHub Desktop.
Arrayの中のHashの特定条件時にキーとバリューを加える
items = [{:title => "a", :price => 70},
{:title => "b", :price => 200},
{:title => "c", :price => 50}]
items.each do |item|
item[:special] = 'Low price!' if item[:price] < 100
end
#[{:title=>"a", :price=>70, :special=>"Low price!"},
# {:title=>"b", :price=>200},
# {:title=>"c", :price=>50, :special=>"Low price!"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment