projects
/
depot.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
End chapter 8
[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
@items
<<
CartItem
.
new
(
product
)
14
end
15
end
16
17
def
total_price
18
@items
.
sum
{|
item
|
item
.
price
}
19
end
20
21
end