Last active
July 6, 2016 02:01
-
-
Save kaochenlong/40da39697fa41528e629fb51d522f216 to your computer and use it in GitHub Desktop.
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
class Product | |
# 實作 | |
end | |
class Cart | |
# 實作 | |
end | |
p1 = Product.new("ruby", 100) | |
p2 = Product.new("php", 200) | |
p3 = Product.new("javascript", 300) | |
p4 = Product.new("perl", 400) | |
p5 = Product.new("python", 600) | |
cart = Cart.new | |
cart.add_item(p1) | |
cart.add_item(p2) | |
cart.add_item(p3) | |
cart.add_item(p4) | |
cart.add_item(p5) | |
list = cart.select { |item| item.price <= 300 } | |
puts list | |
# 得到結果 | |
# title: ruby, price: $100 | |
# title: php, price: $200 | |
# title: javascript, price: $300 |
Author
kaochenlong
commented
Jul 6, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment