projects
/
depot.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
Finished iteration D.3 in chapter 9
[depot.git]
/
app
/
models
/
cart.rb
1
class
Cart
2
attr_reader
:items
3
4
def
initialize
5
@items
= []
6
end
7
8
def
add_product
(
product
)
9
current_item
=
@items
.
find
{|
item
|
item
.
product
==
product
}
10
if
current_item
11
current_item
.
increment_quantity
12
else
13
current_item
=
CartItem
.
new
(
product
)
14
@items
<<
current_item
15
end
16
current_item
17
end
18
19
def
total_price
20
@items
.
sum
{|
item
|
item
.
price
}
21
end
22
23
end