Created
May 24, 2012 13:55
-
-
Save igaiga/2781674 to your computer and use it in GitHub Desktop.
Arrayの中のHashの特定条件時にキーとバリューを加える
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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