@sandimetz Mar 2014
sandi metz
all the little things
Friday, March 7, 14
@sandimetz Mar 2014
Want better apps?
Friday, March 7, 14
@sandimetz Mar 2014
make smaller things
Friday, March 7, 14
@sandimetz Mar 2014
The Gilded Rose Kata
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
#
...
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
#
...
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
#
...
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
#
...
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
#
21
more
lines
def
tick
if
name
!=
'Aged
Brie'
&&
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
quality
<
50
@quality
+=
1
if
name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
days_remaining
<
11
if
quality
<
50
@quality
+=
1
end
end
if
days_remaining
<
6
if
quality
<
50
@quality
+=
1
end
end
end
end
end
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
days_remaining
<
0
if
name
!=
"Aged
Brie"
if
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
quality
-‐
quality
end
else
if
quality
<
50
@quality
+=
1
end
end
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
#
22
previous
lines
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
def
tick
if
name
!=
'Aged
Brie'
&&
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
quality
<
50
@quality
+=
1
if
name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
days_remaining
<
11
if
quality
<
50
@quality
+=
1
end
end
if
days_remaining
<
6
if
quality
<
50
@quality
+=
1
end
end
end
end
end
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
days_remaining
<
0
if
name
!=
"Aged
Brie"
if
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
quality
-‐
quality
end
else
if
quality
<
50
@quality
+=
1
end
end
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
44.7
0
25
50
big conditional
Complexity (Flog)
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
44.7
0
25
50
big conditional
Complexity (Flog)
50
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
44.7
0
25
50
big conditional
Complexity (Flog)
45
tick
50
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
Squint Test
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
changes in shape
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
2
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
changes in color
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
16 if statements
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
16 if statements
7 !=
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
16 if statements
7 !=
2 != with &&
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
16 if statements
7 !=
2 != with &&
3 magic strings
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
16 if statements
7 !=
2 != with &&
3 magic strings
? magic numbers
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
magic strings
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
‘Aged
Brie’
magic strings
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
‘Aged
Brie’
‘Sulfuras,
Hand
of
Ragnaros’
magic strings
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
‘Aged
Brie’
‘Sulfuras,
Hand
of
Ragnaros’
‘Backstage
passes
to
a
TAFKAL80ETC
concert’
magic strings
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
it has tests
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
S..S.S...S..........S....S.....
Fabulous
run
in
0.002800s,
11071.4286
runs/s,
17857.1429
assertions/s.
31
runs,
50
assertions,
0
failures,
0
errors,
6
skips
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
S..S.S...S..........S....S.....
Fabulous
run
in
0.002800s,
11071.4286
runs/s,
17857.1429
assertions/s.
31
runs,
50
assertions,
0
failures,
0
errors,
6
skips
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
def
test_backstage_pass_very_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_lower_bound
def
test_backstage_pass_very_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_on_sell_date
def
test_backstage_pass_after_sell_date
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
def
test_backstage_pass_very_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_lower_bound
def
test_backstage_pass_very_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_on_sell_date
def
test_backstage_pass_after_sell_date
brie
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
def
test_backstage_pass_very_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_lower_bound
def
test_backstage_pass_very_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_on_sell_date
def
test_backstage_pass_after_sell_date
brie
sulfuras
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
def
test_backstage_pass_very_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_lower_bound
def
test_backstage_pass_very_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_on_sell_date
def
test_backstage_pass_after_sell_date
brie
sulfuras
backstage
pass
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
def
test_backstage_pass_very_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_lower_bound
def
test_backstage_pass_very_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_on_sell_date
def
test_backstage_pass_after_sell_date
brie
sulfuras
backstage
pass
normal
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
let’s look at a test
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
name
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
name
quality
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
name
quality
days_remaining
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
reduced by 1
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_conjured_item_before_sell_date
def
test_conjured_item_at_zero_quality
def
test_conjured_item_on_sell_date
def
test_conjured_item_on_sell_date_at_zero_quality
def
test_conjured_item_after_sell_date
def
test_conjured_item_after_sell_date_at_zero_quality
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_conjured_item_before_sell_date
def
test_conjured_item_at_zero_quality
def
test_conjured_item_on_sell_date
def
test_conjured_item_on_sell_date_at_zero_quality
def
test_conjured_item_after_sell_date
def
test_conjured_item_after_sell_date_at_zero_quality
end
6 skipped tests
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_conjured_item_before_sell_date
def
test_conjured_item_at_zero_quality
def
test_conjured_item_on_sell_date
def
test_conjured_item_on_sell_date_at_zero_quality
def
test_conjured_item_after_sell_date
def
test_conjured_item_after_sell_date_at_zero_quality
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_conjured_item_before_sell_date
def
test_conjured_item_at_zero_quality
def
test_conjured_item_on_sell_date
def
test_conjured_item_on_sell_date_at_zero_quality
def
test_conjured_item_after_sell_date
def
test_conjured_item_after_sell_date_at_zero_quality
end
Friday, March 7, 14
@sandimetz Mar 2014
Friday, March 7, 14
@sandimetz Mar 2014
Task:
Friday, March 7, 14
@sandimetz Mar 2014
Task:
Implement Conjured
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_conjured_item_before_sell_date
def
test_conjured_item_at_zero_quality
def
test_conjured_item_on_sell_date
def
test_conjured_item_on_sell_date_at_zero_quality
def
test_conjured_item_after_sell_date
def
test_conjured_item_after_sell_date_at_zero_quality
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_conjured_item_before_sell_date
def
test_conjured_item_at_zero_quality
def
test_conjured_item_on_sell_date
def
test_conjured_item_on_sell_date_at_zero_quality
def
test_conjured_item_after_sell_date
def
test_conjured_item_after_sell_date_at_zero_quality
end
I tried
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_conjured_item_before_sell_date
def
test_conjured_item_at_zero_quality
def
test_conjured_item_on_sell_date
def
test_conjured_item_on_sell_date_at_zero_quality
def
test_conjured_item_after_sell_date
def
test_conjured_item_after_sell_date_at_zero_quality
end
but failed
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_conjured_item_before_sell_date
def
test_conjured_item_at_zero_quality
def
test_conjured_item_on_sell_date
def
test_conjured_item_on_sell_date_at_zero_quality
def
test_conjured_item_after_sell_date
def
test_conjured_item_after_sell_date_at_zero_quality
end
miserably
Friday, March 7, 14
@sandimetz Mar 2014
the pattern failed me
Friday, March 7, 14
@sandimetz Mar 2014
Friday, March 7, 14
@sandimetz Mar 2014
Task:
Friday, March 7, 14
@sandimetz Mar 2014
Task:
Refactor code so I can
Implement Conjured
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
def
test_normal_item_before_sell_date
def
test_normal_item_on_sell_date
def
test_normal_item_after_sell_date
def
test_normal_item_of_zero_quality
normal
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
#
....
def
tick
if
name
!=
'Aged
Brie'
&&
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
quality
<
50
@quality
+=
1
if
name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
days_remaining
<
11
if
quality
<
50
@quality
+=
1
end
end
if
days_remaining
<
6
if
quality
<
50
@quality
+=
1
end
end
end
end
end
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
days_remaining
<
0
if
name
!=
"Aged
Brie"
if
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
quality
-‐
quality
end
else
if
quality
<
50
@quality
+=
1
end
end
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
#
....
def
tick
if
name
!=
'Aged
Brie'
&&
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
quality
<
50
@quality
+=
1
if
name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
days_remaining
<
11
if
quality
<
50
@quality
+=
1
end
end
if
days_remaining
<
6
if
quality
<
50
@quality
+=
1
end
end
end
end
end
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
days_remaining
<
0
if
name
!=
"Aged
Brie"
if
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
quality
-‐
quality
end
else
if
quality
<
50
@quality
+=
1
end
end
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
def
tick
if
name
==
'normal'
return
end
if
name
!=
'Aged
Brie'
&&
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
quality
<
50
@quality
+=
1
if
name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
days_remaining
<
11
if
quality
<
50
@quality
+=
1
end
end
if
days_remaining
<
6
if
quality
<
50
@quality
+=
1
end
end
end
end
end
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
days_remaining
<
0
if
name
!=
"Aged
Brie"
if
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
quality
-‐
quality
end
else
if
quality
<
50
@quality
+=
1
end
end
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
name
==
'normal'
return
end
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
def
tick
if
name
==
'normal'
return
end
if
name
!=
'Aged
Brie'
&&
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
quality
<
50
@quality
+=
1
if
name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
days_remaining
<
11
if
quality
<
50
@quality
+=
1
end
end
if
days_remaining
<
6
if
quality
<
50
@quality
+=
1
end
end
end
end
end
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
days_remaining
<
0
if
name
!=
"Aged
Brie"
if
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
quality
-‐
quality
end
else
if
quality
<
50
@quality
+=
1
end
end
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
.S...S...S..SFF....F.....SS.F..
Fabulous
run
in
0.020340s,
1524.0905
runs/s,
2310.7178
assertions/s.
1)
Failure:
GildedRoseTest#test_normal_item_of_zero_quality
[gilded_rose_test.rb:37]:
Expected:
4
Actual:
5
2)
Failure:
GildedRoseTest#test_normal_item_before_sell_date
[gilded_rose_test.rb:12]:
Expected:
9
Actual:
10
3)
Failure:
GildedRoseTest#test_normal_item_on_sell_date
[gilded_rose_test.rb:20]:
Expected:
8
Actual:
10
4)
Failure:
GildedRoseTest#test_normal_item_after_sell_date
[gilded_rose_test.rb:28]:
Expected:
8
Actual:
10
31
runs,
47
assertions,
4
failures,
0
errors,
6
skips
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
.S...S...S..SFF....F.....SS.F..
Fabulous
run
in
0.020340s,
1524.0905
runs/s,
2310.7178
assertions/s.
1)
Failure:
GildedRoseTest#test_normal_item_of_zero_quality
[gilded_rose_test.rb:37]:
Expected:
4
Actual:
5
2)
Failure:
GildedRoseTest#test_normal_item_before_sell_date
[gilded_rose_test.rb:12]:
Expected:
9
Actual:
10
3)
Failure:
GildedRoseTest#test_normal_item_on_sell_date
[gilded_rose_test.rb:20]:
Expected:
8
Actual:
10
4)
Failure:
GildedRoseTest#test_normal_item_after_sell_date
[gilded_rose_test.rb:28]:
Expected:
8
Actual:
10
31
runs,
47
assertions,
4
failures,
0
errors,
6
skips
4 failures
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
if
name
==
'normal'
return
end
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
#
...
40
more
lines
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
if
name
==
'normal'
return
end
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
#
...
40
more
lines
end
def
normal_tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
if
name
==
'normal'
return
normal_tick
end
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
#
...
40
more
lines
end
def
normal_tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
.S...S...S..SFF....F.....SS.F..
Fabulous
run
in
0.020340s,
1524.0905
runs/s,
2310.7178
assertions/s.
1)
Failure:
GildedRoseTest#test_normal_item_of_zero_quality
[gilded_rose_test.rb:37]:
Expected:
4
Actual:
5
2)
Failure:
GildedRoseTest#test_normal_item_before_sell_date
[gilded_rose_test.rb:12]:
Expected:
9
Actual:
10
3)
Failure:
GildedRoseTest#test_normal_item_on_sell_date
[gilded_rose_test.rb:20]:
Expected:
8
Actual:
10
4)
Failure:
GildedRoseTest#test_normal_item_after_sell_date
[gilded_rose_test.rb:28]:
Expected:
8
Actual:
10
31
runs,
47
assertions,
4
failures,
0
errors,
6
skips
4 failures
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
@quality
-‐=
1
@days_remaining
-‐=
1
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
@quality
-‐=
1
@days_remaining
-‐=
1
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_before_sell_date
item
=
GildedRose.new('normal',
10,
5)
item.tick
assert_equal
9,
item.quality
assert_equal
4,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
@quality
-‐=
1
@days_remaining
-‐=
1
end
end
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
.....S...FS....FS.S...FS....S..
Fabulous
run
in
0.029178s,
1062.4443
runs/s,
1713.6199
assertions/s.
1)
Failure:
GildedRoseTest#test_normal_item_of_zero_quality
[gilded_rose_test.rb:38]:
Expected:
0
Actual:
-‐1
2)
Failure:
GildedRoseTest#test_normal_item_after_sell_date
[gilded_rose_test.rb:30]:
Expected:
8
Actual:
9
3)
Failure:
GildedRoseTest#test_normal_item_on_sell_date
[gilded_rose_test.rb:22]:
Expected:
8
Actual:
9
31
runs,
50
assertions,
3
failures,
0
errors,
6
skips
3 failures
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_on_sell_date
item
=
GildedRose.new('normal',
10,
0)
item.tick
assert_equal
8,
item.quality
assert_equal
-‐1,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
@quality
-‐=
1
@days_remaining
-‐=
1
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_on_sell_date
item
=
GildedRose.new('normal',
10,
0)
item.tick
assert_equal
8,
item.quality
assert_equal
-‐1,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
@quality
-‐=
1
@days_remaining
-‐=
1
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_on_sell_date
item
=
GildedRose.new('normal',
10,
0)
item.tick
assert_equal
8,
item.quality
assert_equal
-‐1,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
@quality
-‐=
1
@days_remaining
-‐=
1
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_on_sell_date
item
=
GildedRose.new('normal',
10,
0)
item.tick
assert_equal
8,
item.quality
assert_equal
-‐1,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
@quality
-‐=
1
@days_remaining
-‐=
1
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_on_sell_date
item
=
GildedRose.new('normal',
10,
0)
item.tick
assert_equal
8,
item.quality
assert_equal
-‐1,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
if
@days_remaining
>
0
@quality
-‐=
1
end
@days_remaining
-‐=
1
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_on_sell_date
item
=
GildedRose.new('normal',
10,
0)
item.tick
assert_equal
8,
item.quality
assert_equal
-‐1,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
if
@days_remaining
>
0
@quality
-‐=
1
end
if
@days_remaining
<=
0
@quality
-‐=
2
end
@days_remaining
-‐=
1
end
end
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
...S.S.....S..S..SF.....S......
Fabulous
run
in
0.019924s,
1555.9125
runs/s,
2459.3455
assertions/s.
1)
Failure:
GildedRoseTest#test_normal_item_of_zero_quality
[gilded_rose_test.rb:37]:
Expected:
0
Actual:
-‐1
31
runs,
49
assertions,
1
failures,
0
errors,
6
skips
1 failure ??
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
...S.S.....S..S..SF.....S......
Fabulous
run
in
0.019924s,
1555.9125
runs/s,
2459.3455
assertions/s.
1)
Failure:
GildedRoseTest#test_normal_item_of_zero_quality
[gilded_rose_test.rb:37]:
Expected:
0
Actual:
-‐1
31
runs,
49
assertions,
1
failures,
0
errors,
6
skips
1 failure ??
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_of_zero_quality
item
=
GildedRose.new('normal',
0,
5)
item.tick
assert_equal
0,
item.quality
assert_equal
4,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
if
@days_remaining
>
0
@quality
-‐=
1
end
if
@days_remaining
<=
0
@quality
-‐=
2
end
@days_remaining
-‐=
1
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_of_zero_quality
item
=
GildedRose.new('normal',
0,
5)
item.tick
assert_equal
0,
item.quality
assert_equal
4,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
if
@days_remaining
>
0
@quality
-‐=
1
end
if
@days_remaining
<=
0
@quality
-‐=
2
end
@days_remaining
-‐=
1
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_of_zero_quality
item
=
GildedRose.new('normal',
0,
5)
item.tick
assert_equal
0,
item.quality
assert_equal
4,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
if
@days_remaining
>
0
@quality
-‐=
1
end
if
@days_remaining
<=
0
@quality
-‐=
2
end
@days_remaining
-‐=
1
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_of_zero_quality
item
=
GildedRose.new('normal',
0,
5)
item.tick
assert_equal
0,
item.quality
assert_equal
4,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
if
@days_remaining
>
0
@quality
-‐=
1
end
if
@days_remaining
<=
0
@quality
-‐=
2
end
@days_remaining
-‐=
1
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
test_normal_item_of_zero_quality
item
=
GildedRose.new('normal',
0,
5)
item.tick
assert_equal
0,
item.quality
assert_equal
4,
item.days_remaining
end
class
GildedRose
#
...
def
normal_tick
if
@quality
!=
0
if
@days_remaining
>
0
@quality
-‐=
1
end
if
@days_remaining
<=
0
@quality
-‐=
2
end
end
@days_remaining
-‐=
1
end
end
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
S..S.S...S..........S....S.....
Fabulous
run
in
0.002800s,
11071.4286
runs/s,
17857.1429
assertions/s.
31
runs,
50
assertions,
0
failures,
0
errors,
6
skips
Friday, March 7, 14
@sandimetz Mar 2014
refactor under green
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
if
@quality
!=
0
if
@days_remaining
>
0
@quality
-‐=
1
end
if
@days_remaining
<=
0
@quality
-‐=
2
end
end
@days_remaining
-‐=
1
end
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
end
def
normal_tick
if
@quality
!=
0
if
@days_remaining
>
0
@quality
-‐=
1
end
if
@days_remaining
<=
0
@quality
-‐=
2
end
end
@days_remaining
-‐=
1
end
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
end
def
normal_tick
if
@quality
!=
0
if
@days_remaining
>
0
@quality
-‐=
1
end
if
@days_remaining
<=
0
@quality
-‐=
2
end
end
@days_remaining
-‐=
1
end
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
end
def
normal_tick
if
@quality
!=
0
if
@days_remaining
>
0
@quality
-‐=
1
end
if
@days_remaining
<=
0
@quality
-‐=
2
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
end
def
normal_tick
if
@quality
!=
0
if
@days_remaining
>
0
@quality
-‐=
1
end
if
@days_remaining
<=
0
@quality
-‐=
2
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
end
def
normal_tick
if
@days_remaining
>
0
@quality
-‐=
1
end
if
@days_remaining
<=
0
@quality
-‐=
2
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
end
def
normal_tick
if
@days_remaining
>
0
@quality
-‐=
1
end
if
@days_remaining
<=
0
@quality
-‐=
2
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
normal_tick
if
@days_remaining
>
0
@quality
-‐=
1
end
if
@days_remaining
<=
0
@quality
-‐=
2
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
normal_tick
end
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
S..S.S...S..........S....S.....
Fabulous
run
in
0.002800s,
11071.4286
runs/s,
17857.1429
assertions/s.
31
runs,
50
assertions,
0
failures,
0
errors,
6
skips
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
if
name
==
'normal'
return
normal_tick
end
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
#
...
40
more
lines
end
end
Reprise
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
if
name
==
'normal'
return
normal_tick
end
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
#
...
40
more
lines
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
if
name
==
'normal'
return
normal_tick
end
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
#
...
40
more
lines
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
if
name
==
'normal'
return
normal_tick
end
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
#
...
40
more
lines
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
normal
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
#
def
test_normal
...
etc
def
test_brie_before_sell_date
def
test_brie_before_sell_date_with_max_quality
def
test_brie_on_sell_date
def
test_brie_on_sell_date_near_max_quality
def
test_brie_on_sell_date_with_max_quality
def
test_brie_after_sell_date
def
test_brie_after_sell_date_with_max_quality
#
def
test_sulfuras
...
etc
#
def
test_backstage
...
etc
end
brie
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
if
name
==
'normal'
return
normal_tick
end
#
...
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
end
#
...
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
end
#
...
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
end
#
...
end
def
brie_tick
end
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
.F...F.....S.S.F..S.FF.S.F.FS.S
Fabulous
run
in
0.027410s,
1130.9741
runs/s,
1678.2196
assertions/s.
1)
Failure:
GildedRoseTest#test_brie_on_sell_date_with_max_quality
[gilded_rose_test.rb:78]:
Expected:
4
Actual:
5
2)
Failure:
GildedRoseTest#test_brie_on_sell_date_near_max_quality
[gilded_rose_test.rb:69]:
Expected:
50
Actual:
49
3)
Failure:
GildedRoseTest#test_brie_on_sell_date
[gilded_rose_test.rb:61]:
Expected:
12
Actual:
10
4)
Failure:
GildedRoseTest#test_brie_after_sell_date_with_max_quality
[gilded_rose_test.rb:94]:
Expected:
-‐11
Actual:
-‐10
5)
Failure:
GildedRoseTest#test_brie_before_sell_date_with_max_quality
[gilded_rose_test.rb:54]:
Expected:
6
Actual:
7
7 failures
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
end
#
...
end
def
brie_tick
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
end
#
...
end
def
brie_tick
end
fast forward...
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
end
#
...
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
end
#
...
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
brie
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
...S......S.....SS.....SS......
Fabulous
run
in
0.003862s,
8026.9291
runs/s,
12946.6598
assertions/s.
31
runs,
50
assertions,
0
failures,
0
errors,
6
skips
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
Similarity
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
Friday, March 7, 14
@sandimetz Mar 2014
duplication is far cheaper
than the wrong abstraction
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
#
def
test_normal
...
etc
#
def
test_brie
...
etc
def
test_sulfuras_before_sell_date
def
test_sulfuras_on_sell_date
def
test_sulfuras_after_sell_date
#
def
test_backstage
...
etc
end
sulfuras
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
end
#
...
end
def
sulfuras_tick
end
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
...S......S.....SS.....SS......
Fabulous
run
in
0.003862s,
8026.9291
runs/s,
12946.6598
assertions/s.
31
runs,
50
assertions,
0
failures,
0
errors,
6
skips
0 failures ?!?
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
end
#
...
end
def
sulfuras_tick
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
end
#
...
end
def
sulfuras_tick
end
nothing changes
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
end
#
...
end
def
sulfuras_tick
end
sulfuras
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRoseTest
<
Minitest::Test
#
def
test_normal
...
etc
#
def
test_brie
...
etc
#
def
test_sulfuras
...
etc
def
test_backstage_pass_long_before_sell_date
def
test_backstage_pass_medium_close_to_sell_date_upper_bound
def
test_backstage_pass_medium_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_medium_close_to_sell_date_lower_bound
def
test_backstage_pass_medium_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_upper_bound
def
test_backstage_pass_very_close_to_sell_date_upper_bound_at_max_quality
def
test_backstage_pass_very_close_to_sell_date_lower_bound
def
test_backstage_pass_very_close_to_sell_date_lower_bound_at_max_quality
def
test_backstage_pass_on_sell_date
def
test_backstage_pass_after_sell_date
end
backstage
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
when
'Aged
Brie'
when
'Sulfuras,
Hand
of
Ragnaros'
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
return
backstage_tick
end
#
...
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
backstage
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
...S......S.....SS.....SS......
Fabulous
run
in
0.003472s,
8928.5714
runs/s,
14400.9217
assertions/s.
31
runs,
50
assertions,
0
failures,
0
errors,
6
skips
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
return
backstage_tick
end
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
#
...
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
def
sulfuras_tick
def
backstage_tick
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remai
end
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
return
backstage_tick
end
if
name
!=
'Aged
Brie'
&&
name
!=
'Backstage
passes
to
a
TAF
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
quality
<
50
@quality
+=
1
if
name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
days_remaining
<
11
if
quality
<
50
@quality
+=
1
end
end
if
days_remaining
<
6
if
quality
<
50
@quality
+=
1
end
end
end
end
end
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
days_remaining
<
0
if
name
!=
"Aged
Brie"
if
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
quality
-‐
quality
end
else
if
quality
<
50
@quality
+=
1
end
end
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
return
backstage_tick
end
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
#
...
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
def
sulfuras_tick
def
backstage_tick
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remai
end
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
return
backstage_tick
end
if
name
!=
'Aged
Brie'
&&
name
!=
'Backstage
passes
to
a
TAF
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
quality
<
50
@quality
+=
1
if
name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
days_remaining
<
11
if
quality
<
50
@quality
+=
1
end
end
if
days_remaining
<
6
if
quality
<
50
@quality
+=
1
end
end
end
end
end
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
days_remaining
<
0
if
name
!=
"Aged
Brie"
if
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
quality
-‐
quality
end
else
if
quality
<
50
@quality
+=
1
end
end
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
return
backstage_tick
end
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
#
...
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
def
sulfuras_tick
def
backstage_tick
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remai
end
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
return
backstage_tick
end
if
name
!=
'Aged
Brie'
&&
name
!=
'Backstage
passes
to
a
TAF
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
quality
<
50
@quality
+=
1
if
name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
days_remaining
<
11
if
quality
<
50
@quality
+=
1
end
end
if
days_remaining
<
6
if
quality
<
50
@quality
+=
1
end
end
end
end
end
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
days_remaining
<
0
if
name
!=
"Aged
Brie"
if
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
quality
-‐
quality
end
else
if
quality
<
50
@quality
+=
1
end
end
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
return
backstage_tick
end
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
#
...
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
def
sulfuras_tick
def
backstage_tick
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remai
end
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
return
backstage_tick
end
if
name
!=
'Aged
Brie'
&&
name
!=
'Backstage
passes
to
a
TAF
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
quality
<
50
@quality
+=
1
if
name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
days_remaining
<
11
if
quality
<
50
@quality
+=
1
end
end
if
days_remaining
<
6
if
quality
<
50
@quality
+=
1
end
end
end
end
end
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
days_remaining
<
0
if
name
!=
"Aged
Brie"
if
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
quality
-‐
quality
end
else
if
quality
<
50
@quality
+=
1
end
end
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
return
backstage_tick
end
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
#
...
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
def
sulfuras_tick
def
backstage_tick
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remai
end
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
return
backstage_tick
end
if
name
!=
'Aged
Brie'
&&
name
!=
'Backstage
passes
to
a
TAF
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
quality
<
50
@quality
+=
1
if
name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
days_remaining
<
11
if
quality
<
50
@quality
+=
1
end
end
if
days_remaining
<
6
if
quality
<
50
@quality
+=
1
end
end
end
end
end
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
days_remaining
<
0
if
name
!=
"Aged
Brie"
if
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
quality
-‐
quality
end
else
if
quality
<
50
@quality
+=
1
end
end
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
return
backstage_tick
end
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
#
...
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
def
sulfuras_tick
def
backstage_tick
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remai
end
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
return
backstage_tick
end
if
name
!=
'Aged
Brie'
&&
name
!=
'Backstage
passes
to
a
TAF
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
quality
<
50
@quality
+=
1
if
name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
days_remaining
<
11
if
quality
<
50
@quality
+=
1
end
end
if
days_remaining
<
6
if
quality
<
50
@quality
+=
1
end
end
end
end
end
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
days_remaining
<
0
if
name
!=
"Aged
Brie"
if
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
quality
-‐
quality
end
else
if
quality
<
50
@quality
+=
1
end
end
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
return
backstage_tick
end
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
c
#
...
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
def
sulfuras_tick
def
backstage_tick
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remai
end
def
tick
case
name
when
'normal'
return
normal_tick
when
'Aged
Brie'
return
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
return
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
return
backstage_tick
end
if
name
!=
'Aged
Brie'
&&
name
!=
'Backstage
passes
to
a
TAF
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
quality
<
50
@quality
+=
1
if
name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
days_remaining
<
11
if
quality
<
50
@quality
+=
1
end
end
if
days_remaining
<
6
if
quality
<
50
@quality
+=
1
end
end
end
end
end
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
days_remaining
<
0
if
name
!=
"Aged
Brie"
if
name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
quality
>
0
if
name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
quality
-‐
quality
end
else
if
quality
<
50
@quality
+=
1
end
end
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
...S......S.....SS.....SS......
Fabulous
run
in
0.003472s,
8928.5714
runs/s,
14400.9217
assertions/s.
31
runs,
50
assertions,
0
failures,
0
errors,
6
skips
Friday, March 7, 14
@sandimetz Mar 2014
small methods are simple
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
small methods
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
big conditional small methods
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
0
25
50
big conditional
Total Complexity
50
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
0
25
50
big conditional small methods
tick normal brie backstage other
40
Total Complexity
50
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
0
25
50
big conditional small methods
tick normal brie backstage other
12
40
45
Total Complexity
50
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
Complexity
50
big conditional
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
0
45
90
Complexity
50
big conditional
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
0
45
90
Complexity
50
84
40
small methods
big conditional 10 Refactorings
Friday, March 7, 14
@sandimetz Mar 2014
Task:
Implement Conjured
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
def
normal_tick
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
def
normal_tick
def
brie_tick
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
def
normal_tick
def
brie_tick
def
sulfuras_tick
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
def
normal_tick
def
brie_tick
def
sulfuras_tick
def
backstage_tick
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
def
normal_tick
def
brie_tick
def
sulfuras_tick
def
backstage_tick
def
conjured_tick
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
def
normal_tick
def
brie_tick
def
sulfuras_tick
def
backstage_tick
def
conjured_tick
???
Friday, March 7, 14
@sandimetz Mar 2014
the pattern still fails me
Friday, March 7, 14
@sandimetz Mar 2014
open / closed
Friday, March 7, 14
@sandimetz Mar 2014
open for extension
Friday, March 7, 14
@sandimetz Mar 2014
open for extension
closed for modification
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
def
normal_tick
def
brie_tick
def
sulfuras_tick
def
backstage_tick
Friday, March 7, 14
@sandimetz Mar 2014
they’re screaming to get out
Friday, March 7, 14
@sandimetz Mar 2014
GildedRose
Friday, March 7, 14
@sandimetz Mar 2014
brie_tick
backstage_tick
sulfuras_tick
normal_tick
GildedRose
Friday, March 7, 14
@sandimetz Mar 2014
brie_tick
backstage_tick
sulfuras_tick
normal_tick
GildedRose
Friday, March 7, 14
@sandimetz Mar 2014
Normal
brie_tick
backstage_tick
sulfuras_tick
normal_tick
GildedRose
Friday, March 7, 14
@sandimetz Mar 2014
tick
Normal
brie_tick
backstage_tick
sulfuras_tick
normal_tick
GildedRose
Friday, March 7, 14
@sandimetz Mar 2014
tick
Normal
brie_tick
backstage_tick
sulfuras_tick
normal_tick
GildedRose
Friday, March 7, 14
@sandimetz Mar 2014
tick
Normal
brie_tick
backstage_tick
sulfuras_tick
normal_tick
GildedRose
Friday, March 7, 14
@sandimetz Mar 2014
tick
Normal
brie_tick
backstage_tick
sulfuras_tick
GildedRose
Friday, March 7, 14
@sandimetz Mar 2014
tick
Normal
GildedRose
brie_tick
backstage_tick
sulfuras_tick
Friday, March 7, 14
@sandimetz Mar 2014
tick
Normal
GildedRose
brie_tick
backstage_tick
sulfuras_tick
Friday, March 7, 14
@sandimetz Mar 2014
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
Friday, March 7, 14
@sandimetz Mar 2014
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
Friday, March 7, 14
@sandimetz Mar 2014
class
Normal
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
Normal
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
Normal
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
Normal
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
normal_tick
end
class
Normal
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
normal_tick
@item
=
Normal.new(quality,
days_remaining)
end
class
Normal
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
normal_tick
@item
=
Normal.new(quality,
days_remaining)
item.tick
end
class
Normal
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
Friday, March 7, 14
@sandimetz Mar 2014
tick
Normal
GildedRose
brie_tick
backstage_tick
sulfuras_tick
Friday, March 7, 14
@sandimetz Mar 2014
normal is an object
Friday, March 7, 14
@sandimetz Mar 2014
brie/sulfuras/backstage are not
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
normal_tick
@item
=
Normal.new(quality,
days_remaining)
item.tick
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
normal_tick
@item
=
Normal.new(quality,
days_remaining)
item.tick
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
normal_tick
@item
=
Normal.new(quality,
days_remaining)
item.tick
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
quality
end
def
days_remaining
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
normal_tick
@item
=
Normal.new(quality,
days_remaining)
item.tick
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
quality
return
item.quality
if
item
end
def
days_remaining
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
normal_tick
@item
=
Normal.new(quality,
days_remaining)
item.tick
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
quality
return
item.quality
if
item
@quality
end
def
days_remaining
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
normal_tick
@item
=
Normal.new(quality,
days_remaining)
item.tick
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
quality
return
item.quality
if
item
@quality
end
def
days_remaining
return
item.days_remaining
if
item
@days_remaining
end
Friday, March 7, 14
@sandimetz Mar 2014
brie
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
class
Brie
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
class
Brie
def
tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
brie_tick
end
class
Brie
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
brie_tick
end
class
Brie
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
brie_tick
@item
=
Brie.new(quality,
days_remaining)
item.tick
end
class
Brie
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
Friday, March 7, 14
@sandimetz Mar 2014
sulfuras
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
sulfuras_tick
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
sulfuras_tick
end
class
Sulfuras
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
sulfuras_tick
end
class
Sulfuras
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
sulfuras_tick
@item
=
Sulfuras.new(quality,
days_remaining)
item.tick
end
class
Sulfuras
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
backstage
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
class
Backstage
def
tick
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
backstage_tick
end
class
Backstage
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
backstage_tick
end
class
Backstage
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
backstage_tick
end
class
Backstage
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
backstage_tick
end
class
Backstage
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
backstage_tick
@item
=
Backstage.new(quality,
days_remaining)
item.tick
end
class
Backstage
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
Friday, March 7, 14
@sandimetz Mar 2014
normal/brie/sulfuras/backstage
are now objects
Friday, March 7, 14
@sandimetz Mar 2014
GildedRose
tick
Normal
tick
Brie
tick
Sulfuras
attr_reader
:item
tick
Backstage
attr_reader
:quality,
:days_remaining
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@item
=
Normal.new(quality,
days_remaining)
item.tick
end
def
brie_tick
@item
=
Brie.new(quality,
days_remaining)
item.tick
end
#
etc
Friday, March 7, 14
@sandimetz Mar 2014
rewind
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@item
=
Normal.new(quality,
days_remaining)
item.tick
end
def
brie_tick
@item
=
Brie.new(quality,
days_remaining)
item.tick
end
#
etc
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@item
=
Normal.new(quality,
days_remaining)
item.tick
end
def
brie_tick
@item
=
Brie.new(quality,
days_remaining)
item.tick
end
#
etc
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
case
name
when
'normal'
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@item
=
Normal.new(quality,
days_remaining)
item.tick
end
def
brie_tick
@item
=
Brie.new(quality,
days_remaining)
item.tick
end
#
etc
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
case
name
when
'normal'
@item
=
Normal.new(quality,
days_remaining)
item.tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
end
def
brie_tick
@item
=
Brie.new(quality,
days_remaining)
item.tick
end
#
etc
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
case
name
when
'normal'
@item
=
Normal.new(quality,
days_remaining)
item.tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
brie_tick
@item
=
Brie.new(quality,
days_remaining)
item.tick
end
#
etc
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
case
name
when
'normal'
@item
=
Normal.new(quality,
days_remaining)
item.tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
brie_tick
@item
=
Brie.new(quality,
days_remaining)
item.tick
end
#
etc
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
case
name
when
'normal'
@item
=
Normal.new(quality,
days_remaining)
item.tick
when
'Aged
Brie'
when
'Sulfuras,
Hand
of
Ragnaros'
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
end
end
def
brie_tick
@item
=
Brie.new(quality,
days_remaining)
item.tick
end
#
etc
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
case
name
when
'normal'
@item
=
Normal.new(quality,
days_remaining)
item.tick
when
'Aged
Brie'
@item
=
Brie.new(quality,
days_remaining)
item.tick
when
'Sulfuras,
Hand
of
Ragnaros'
@item
=
Sulfuras.new(quality,
days_remaining)
item.tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
@item
=
Backstage.new(quality,
days_remaining)
item.tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
abstract away the duplication
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
case
name
when
'normal'
@item
=
Normal.new(quality,
days_remaining)
item.tick
when
'Aged
Brie'
@item
=
Brie.new(quality,
days_remaining)
item.tick
when
'Sulfuras,
Hand
of
Ragnaros'
@item
=
Sulfuras.new(quality,
days_remaining)
item.tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
@item
=
Backstage.new(quality,
days_remaining)
item.tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
def
tick
case
name
when
'normal'
@item
=
Normal.new(quality,
days_remaining)
item.tick
when
'Aged
Brie'
@item
=
Brie.new(quality,
days_remaining)
item.tick
when
'Sulfuras,
Hand
of
Ragnaros'
@item
=
Sulfuras.new(quality,
days_remaining)
item.tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
@item
=
Backstage.new(quality,
days_remaining)
item.tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:item
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
case
name
when
'normal'
@item
=
Normal.new(quality,
days_remaining)
item.tick
when
'Aged
Brie'
@item
=
Brie.new(quality,
days_remaining)
item.tick
when
'Sulfuras,
Hand
of
Ragnaros'
@item
=
Sulfuras.new(quality,
days_remaining)
item.tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
@item
=
Backstage.new(quality,
days_remaining)
item.tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:item
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
case
name
when
'normal'
@item
=
Normal.new(quality,
days_remaining)
item.tick
when
'Aged
Brie'
@item
=
Brie.new(quality,
days_remaining)
item.tick
when
'Sulfuras,
Hand
of
Ragnaros'
@item
=
Sulfuras.new(quality,
days_remaining)
item.tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
@item
=
Backstage.new(quality,
days_remaining)
item.tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:item
def
initialize(name,
quality,
days_remaining)
@item
=
???
end
def
tick
case
name
when
'normal'
@item
=
Normal.new(quality,
days_remaining)
item.tick
when
'Aged
Brie'
@item
=
Brie.new(quality,
days_remaining)
item.tick
when
'Sulfuras,
Hand
of
Ragnaros'
@item
=
Sulfuras.new(quality,
days_remaining)
item.tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
@item
=
Backstage.new(quality,
days_remaining)
item.tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:item
def
initialize(name,
quality,
days_remaining)
@item
=
???
end
def
tick
case
name
when
'normal'
@item
=
Normal.new(quality,
days_remaining)
item.tick
when
'Aged
Brie'
@item
=
Brie.new(quality,
days_remaining)
item.tick
when
'Sulfuras,
Hand
of
Ragnaros'
@item
=
Sulfuras.new(quality,
days_remaining)
item.tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
@item
=
Backstage.new(quality,
days_remaining)
item.tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:item
def
initialize(name,
quality,
days_remaining)
@item
=
???.new(quality,
days_remaining)
end
def
tick
case
name
when
'normal'
@item
=
Normal.new(quality,
days_remaining)
item.tick
when
'Aged
Brie'
@item
=
Brie.new(quality,
days_remaining)
item.tick
when
'Sulfuras,
Hand
of
Ragnaros'
@item
=
Sulfuras.new(quality,
days_remaining)
item.tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
@item
=
Backstage.new(quality,
days_remaining)
item.tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:item
def
initialize(name,
quality,
days_remaining)
@item
=
???.new(quality,
days_remaining)
end
def
tick
case
name
when
'normal'
@item
=
Normal.new(quality,
days_remaining)
item.tick
when
'Aged
Brie'
@item
=
Brie.new(quality,
days_remaining)
item.tick
when
'Sulfuras,
Hand
of
Ragnaros'
@item
=
Sulfuras.new(quality,
days_remaining)
item.tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
@item
=
Backstage.new(quality,
days_remaining)
item.tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:item
def
initialize(name,
quality,
days_remaining)
@item
=
???.new(quality,
days_remaining)
end
def
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Sulfuras
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:item
def
initialize(name,
quality,
days_remaining)
@item
=
???.new(quality,
days_remaining)
end
def
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Sulfuras
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:item
def
initialize(name,
quality,
days_remaining)
@item
=
???.new(quality,
days_remaining)
end
def
klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Sulfuras
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Sulfuras
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Sulfuras
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Sulfuras
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
#
...
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
#
...
end
def
tick
item.tick
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
return
item.quality
if
item
@quality
end
def
days_remaining
return
item.days_remaining
if
item
@days_remaining
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
return
item.quality
if
item
@quality
end
def
days_remaining
return
item.days_remaining
if
item
@days_remaining
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
return
item.quality
if
item
end
def
days_remaining
return
item.days_remaining
if
item
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
return
item.quality
if
item
end
def
days_remaining
return
item.days_remaining
if
item
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
return
item.quality
if
item
end
def
days_remaining
return
item.days_remaining
if
item
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
item is a role
Friday, March 7, 14
@sandimetz Mar 2014
GildedRose
tick
Normal
tick
Brie
tick
Sulfuras
attr_reader
:item
tick
Backstage
attr_reader
:quality,
:days_remaining
Friday, March 7, 14
@sandimetz Mar 2014
attr_reader
:item
GildedRose
ItemRole
def
tick
def
quality
def
days_remaining
Friday, March 7, 14
@sandimetz Mar 2014
attr_reader
:item
ItemRole
def
tick
def
quality
def
days_remaining
GildedRose
Friday, March 7, 14
@sandimetz Mar 2014
attr_reader
:item
def
tick
end
def
quality
end
def
days_remaining
end
ItemRole
def
tick
def
quality
def
days_remaining
GildedRose
Friday, March 7, 14
@sandimetz Mar 2014
attr_reader
:item
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
GildedRose
ItemRole
def
tick
def
quality
def
days_remaining
Friday, March 7, 14
@sandimetz Mar 2014
attr_reader
:item
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
GildedRose
ItemRole
def
tick
def
quality
def
days_remaining
Friday, March 7, 14
@sandimetz Mar 2014
Foo
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
attr_reader
:item
GildedRose
ItemRole
def
tick
def
quality
def
days_remaining
Friday, March 7, 14
@sandimetz Mar 2014
Foo
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
attr_reader
:item
attr_reader
:rose
GildedRose
ItemRole
def
tick
def
quality
def
days_remaining
Friday, March 7, 14
@sandimetz Mar 2014
Foo
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
attr_reader
:item
attr_reader
:rose
def
doit
rose.tick
rose.quality
rose.days_remaining
end
GildedRose
ItemRole
def
tick
def
quality
def
days_remaining
Friday, March 7, 14
@sandimetz Mar 2014
Foo
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
attr_reader
:item
attr_reader
:rose
def
doit
rose.tick
rose.quality
rose.days_remaining
end
GildedRose
ItemRole
def
tick
def
quality
def
days_remaining
Friday, March 7, 14
@sandimetz Mar 2014
Foo
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
attr_reader
:item
attr_reader
:rose
def
doit
rose.tick
rose.quality
rose.days_remaining
end
GildedRose
ItemRole
def
tick
def
quality
def
days_remaining
Friday, March 7, 14
@sandimetz Mar 2014
Foo
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
attr_reader
:item
attr_reader
:rose
def
doit
rose.tick
rose.quality
rose.days_remaining
end
GildedRose
ItemRole
def
tick
def
quality
def
days_remaining
Middleman
Friday, March 7, 14
@sandimetz Mar 2014
Foo
attr_reader
:item
attr_reader
:rose
GildedRose
ItemRole
def
tick
def
quality
def
days_remaining
Friday, March 7, 14
@sandimetz Mar 2014
Foo
attr_reader
:item
attr_reader
:rose
def
getit
@rose
=
GildedRose.new(
‘normal’,
...)
end
GildedRose
ItemRole
def
tick
def
quality
def
days_remaining
Friday, March 7, 14
@sandimetz Mar 2014
Foo
def
initialize(name,...)
@item
=
klass_for(name).
new(
quality,
days_remaining)
end
def
klass_for(name)
case
name
when
'normal'
Normal
attr_reader
:item
attr_reader
:rose
def
getit
@rose
=
GildedRose.new(
‘normal’,
...)
end
GildedRose
ItemRole
def
tick
def
quality
def
days_remaining
Friday, March 7, 14
@sandimetz Mar 2014
Foo
def
initialize(name,...)
@item
=
klass_for(name).
new(
quality,
days_remaining)
end
def
klass_for(name)
case
name
when
'normal'
Normal
attr_reader
:item
attr_reader
:rose
def
getit
@rose
=
GildedRose.new(
‘normal’,
...)
end
GildedRose
ItemRole
def
tick
def
quality
def
days_remaining
Item
Factory
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
attr_reader
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
attr_reader
:item
def
initialize(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
attr_reader
:item
def
self.for(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
attr_reader
:item
def
self.for(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
attr_reader
:item
def
self.for(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
self.klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
attr_reader
:item
def
self.for(name,
quality,
days_remaining)
@item
=
klass_for(name).new(quality,
days_remaining)
end
def
self.klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
attr_reader
:item
def
self.for(name,
quality,
days_remaining)
klass_for(name).new(quality,
days_remaining)
end
def
self.klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
attr_reader
:item
def
self.for(name,
quality,
days_remaining)
klass_for(name).new(quality,
days_remaining)
end
def
self.klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
def
self.for(name,
quality,
days_remaining)
klass_for(name).new(quality,
days_remaining)
end
def
self.klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
def
self.for(name,
quality,
days_remaining)
klass_for(name).new(quality,
days_remaining)
end
def
self.klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
def
self.for(name,
quality,
days_remaining)
klass_for(name).new(quality,
days_remaining)
end
def
self.klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
def
self.for(name,
quality,
days_remaining)
klass_for(name).new(quality,
days_remaining)
end
def
self.klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Middleman
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
def
self.for(name,
quality,
days_remaining)
klass_for(name).new(quality,
days_remaining)
end
def
self.klass_for(name)
#
...
end
def
tick
item.tick
end
def
quality
item.quality
end
def
days_remaining
item.days_remaining
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Middleman
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
def
self.for(name,
quality,
days_remaining)
klass_for(name).new(quality,
days_remaining)
end
def
self.klass_for(name)
#
...
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
Foo
def
self.for(name,...)
end
attr_reader
:rose
def
getit
@rose
=
GildedRose.for(
‘normal’,
...)
end
GildedRose
Friday, March 7, 14
@sandimetz Mar 2014
Foo
attr_reader
:rose
def
getit
@rose
=
GildedRose.for(
‘normal’,
...)
end
ItemRole
def
tick
def
quality
def
days_remaining
def
self.for(name,...)
end
GildedRose
Friday, March 7, 14
@sandimetz Mar 2014
extract common code
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
def
self.for(name,
quality,
days_remaining)
klass_for(name).new(quality,
days_remaining)
end
def
self.klass_for(name)
#
...
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
def
self.for(name,
quality,
days_remaining)
klass_for(name).new(quality,
days_remaining)
end
def
self.klass_for(name)
#
...
end
class
Normal
class
Brie
class
Sulfuras
class
Backstage
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Normal
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
#
...
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Normal
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
#
...
end
end
class
Brie
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
#
...
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Normal
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
#
...
end
end
class
Brie
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
#
...
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Normal
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
#
...
end
end
class
Brie
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
#
...
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Normal
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
#
...
end
end
class
Brie
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
end
class
Normal
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
#
...
end
end
class
Brie
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
end
class
Normal
def
tick
#
...
end
end
class
Brie
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
end
class
Normal
<
Item
def
tick
#
...
end
end
class
Brie
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
end
class
Normal
<
Item
def
tick
#
...
end
end
class
Brie
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
#
...
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
end
class
Normal
<
Item
def
tick
#
...
end
end
class
Brie
<
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
#
...
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
end
class
Normal
<
Item
def
tick
#
...
end
end
class
Brie
<
Item
def
tick
#
...
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
end
class
Normal
<
Item
def
tick
#
...
end
end
class
Brie
<
Item
def
tick
#
...
end
end
class
Sulfuras
<
Item
def
tick
end
end
class
Backstage
<
Item
def
tick
Friday, March 7, 14
@sandimetz Mar 2014
inheritance is not evil
Friday, March 7, 14
@sandimetz Mar 2014
but programmers sometimes are
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
end
class
Normal
<
Item
def
tick
#
...
end
end
class
Brie
<
Item
def
tick
#
...
end
end
class
Sulfuras
<
Item
def
tick
end
end
class
Backstage
<
Item
def
tick
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
end
class
Normal
<
Item
def
tick
#
...
end
end
class
Brie
<
Item
def
tick
#
...
end
end
class
Sulfuras
<
Item
def
tick
end
end
class
Backstage
<
Item
def
tick
Item
quality
days_remaining
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
end
class
Normal
<
Item
def
tick
#
...
end
end
class
Brie
<
Item
def
tick
#
...
end
end
class
Sulfuras
<
Item
def
tick
end
end
class
Backstage
<
Item
def
tick
Item
quality
days_remaining
Normal
Brie
Sulfuras
Backstage
quality
days_remaining
tick
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
end
class
Normal
<
Item
def
tick
#
...
end
end
class
Brie
<
Item
def
tick
#
...
end
end
class
Sulfuras
<
Item
def
tick
end
end
class
Backstage
<
Item
def
tick
Item
quality
days_remaining
Normal
Brie
Sulfuras
Backstage
quality
days_remaining
tick
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
end
class
Normal
<
Item
def
tick
#
...
end
end
class
Brie
<
Item
def
tick
#
...
end
end
class
Sulfuras
<
Item
def
tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
#
...
end
end
class
Brie
<
Item
def
tick
#
...
end
end
class
Sulfuras
<
Item
def
tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
#
...
end
end
class
Brie
<
Item
def
tick
#
...
end
end
class
Sulfuras
<
Item
def
tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Sulfuras
<
Item
def
tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Sulfuras
<
Item
def
tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
def
tick
end
end
class
Sulfuras
<
Item
def
tick
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
def
tick
end
end
class
Sulfuras
<
Item
def
tick
end
end
def
self.klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Sulfuras
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
def
tick
end
end
class
Sulfuras
<
Item
def
tick
end
end
def
self.klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Sulfuras
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
def
tick
end
end
class
Sulfuras
<
Item
def
tick
end
end
def
self.klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Item
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
def
tick
end
end
class
Sulfuras
<
Item
def
tick
end
end
def
self.klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Item
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
def
tick
end
end
def
self.klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Item
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
def
tick
end
end
def
self.klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Item
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
def
tick
end
end
def
self.klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Item
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
Friday, March 7, 14
@sandimetz Mar 2014
extract configuration
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
def
self.for(name,
quality,
days_remaining)
klass_for(name).new(quality,
days_remaining)
end
def
self.klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Item
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
klass_for(name).new(quality,
days_remaining)
end
def
self.klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Item
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
klass_for(name).new(quality,
days_remaining)
end
def
self.klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Item
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
klass_for(name).
new(quality,
days_remaining)
end
def
self.klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Item
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).
new(quality,
days_remaining)
end
def
self.klass_for(name)
case
name
when
'normal'
Normal
when
'Aged
Brie'
Brie
when
'Sulfuras,
Hand
of
Ragnaros'
Item
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
Backstage
end
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).
new(quality,
days_remaining)
end
end
Friday, March 7, 14
@sandimetz Mar 2014
small objects
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).
new(quality,
days_remaining)
end
end module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
days_remainin
end
end small objects
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
days_remainin
end
end small objects
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
if
@name
!=
'Aged
Brie'
&&
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
if
@quality
<
50
@quality
+=
1
if
@name
==
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@days_remaining
<
11
if
@quality
<
50
@quality
+=
1
end
end
if
@days_remaining
<
6
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@days_remaining
-‐=
1
end
if
@days_remaining
<
0
if
@name
!=
"Aged
Brie"
if
@name
!=
'Backstage
passes
to
a
TAFKAL80ETC
concert'
if
@quality
>
0
if
@name
!=
'Sulfuras,
Hand
of
Ragnaros'
@quality
-‐=
1
end
end
else
@quality
=
@quality
-‐
@quality
end
else
if
@quality
<
50
@quality
+=
1
end
end
end
end
end
big conditional
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
days_remainin
end
end
small methods
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
small objects
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
days_remaining)
end
end
0
25
50
big conditional small methods small objects
tick/for normal brie backstage other
Total Complexity
40
50
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
days_remaining)
end
end
0
25
50
big conditional small methods small objects
tick/for normal brie backstage other
33
40
50
Total Complexity
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
big conditional small methods small objects
50
84
40
Total Complexity
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
0
45
90
big conditional small methods small objects
50
84
40
Total Complexity
Friday, March 7, 14
@sandimetz Mar 2014
class
GildedRose
attr_reader
:name,
:quality,
:days_remaining
def
initialize(name,
quality,
days_remaining)
@name,
@quality,
@days_remaining
=
name,
quality,
days_remaining
end
def
tick
case
name
when
'normal'
normal_tick
when
'Aged
Brie'
brie_tick
when
'Sulfuras,
Hand
of
Ragnaros'
sulfuras_tick
when
'Backstage
passes
to
a
TAFKAL80ETC
concert'
backstage_tick
end
end
def
normal_tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
def
brie_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
def
sulfuras_tick
end
def
backstage_tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
0
45
90
big conditional small methods small objects
50
84
40 33
86
Total Complexity
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
days_remaining)
end
end
0
25
50
big cond small meth small objs
tick/for normal brie backstage other
33
Complexity
40
50
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
days_remaining)
end
end
0
25
50
GildedRose small meth small objs
tick/for normal brie backstage other
33
Complexity
40
50
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
days_remaining)
end
end
0
25
50
GildedRose GildedRose(2) small objs
tick/for normal brie backstage other
33
Complexity
40
50
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
days_remaining)
end
end
0
25
50
GildedRose GildedRose(2) many objs
tick/for normal brie backstage other
33
Complexity
40
50
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
days_remaining)
end
end
0
25
50
GildedRose GildedRose(2) many objs
tick/for normal brie backstage other
33
Complexity
40
50
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
days_remaining)
end
end
0
25
50
GildedRose GildedRose(2) many objs Backstage
tick/for normal brie backstage other
33
Complexity
40
50
12
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
days_remaining)
end
end
0
25
50
GildedRose GildedRose(2) many objs Backstage average
tick/for normal brie backstage other
33
Complexity
40
50
7
12
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
days_remaining)
end
end
0
25
50
GildedRose Backstage
Complexity
50
12
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Item
attr_reader
:quality,
:days_remaining
def
initialize(quality,
days_remaining)
@quality,
@days_remaining
=
quality,
days_remaining
end
def
tick
end
end
class
Normal
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
1
@quality
-‐=
1
if
@days_remaining
<=
0
end
end
class
Brie
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
@quality
+=
1
@quality
+=
1
if
@days_remaining
<=
0
end
end
class
Backstage
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
>=
50
return
@quality
=
0
if
@days_remaining
<
0
@quality
+=
1
@quality
+=
1
if
@days_remaining
<
10
@quality
+=
1
if
@days_remaining
<
5
end
end
DEFAULT_CLASS
=
Item
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage
}
def
self.for(name,
quality,
days_remaining)
(SPECIALIZED_CLASSES[name]
||
DEFAULT_CLASS).new(quality,
days_remaining)
end
end
0
25
50
GildedRose Backstage
Complexity
50
12
75%
Friday, March 7, 14
@sandimetz Mar 2014
Task:
Implement Conjured
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Conjured
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
2
@quality
-‐=
2
if
@days_remaining
<=
0
end
end
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Conjured
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
2
@quality
-‐=
2
if
@days_remaining
<=
0
end
end
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage}
Friday, March 7, 14
@sandimetz Mar 2014
module
GildedRose
class
Conjured
<
Item
def
tick
@days_remaining
-‐=
1
return
if
@quality
==
0
@quality
-‐=
2
@quality
-‐=
2
if
@days_remaining
<=
0
end
end
SPECIALIZED_CLASSES
=
{
'normal'
=>
Normal,
'Aged
Brie'
=>
Brie,
'Backstage
passes
to
a
TAFKAL80ETC
concert'
=>
Backstage,
'Conjured
Mana
Cake'
=>
Conjured
}
Friday, March 7, 14
@sandimetz Mar 2014
#
Running:
...............................
Fabulous
run
in
0.003917s,
7914.2201
runs/s,
15828.4401
assertions/s.
31
runs,
62
assertions,
0
failures,
0
errors,
0
skips
Friday, March 7, 14
@sandimetz Mar 2014
Summary
Friday, March 7, 14
@sandimetz Mar 2014
duplication is far cheaper
than the wrong abstraction
Friday, March 7, 14
@sandimetz Mar 2014
reach for open / closed
Friday, March 7, 14
@sandimetz Mar 2014
small methods are simple
Friday, March 7, 14
@sandimetz Mar 2014
small objects are simple
Friday, March 7, 14
@sandimetz Mar 2014
refactor through complexity
Friday, March 7, 14
@sandimetz Mar 2014
refactor into simplicity
Friday, March 7, 14
@sandimetz Mar 2014
Friday, March 7, 14
@sandimetz Mar 2014
Thanks
Friday, March 7, 14
@sandimetz Mar 2014
Thanks
Jim
Friday, March 7, 14
@sandimetz Mar 2014
Questions?
Friday, March 7, 14
http://poodr.com
Sandi Metz
@sandimetz
@sandimetz Mar 2014
Friday, March 7, 14