He who enjoys doing and enjoys what he has done is happy. - Fortune Cookie
I needed a simple breadcrumb module/class that would let me set the first crumb and add to it later. I looked at www.ruby-toolbox.com and saw a bunch, none of them looked simple enough for me. I already had a template so I dont care about changing that…so I whipped up my own breadcrumbs:
After watching www.rubytapas.com talk about using Struct (I had never really used it before or understood why not just make a class). At first I defined crumb outside of Breadcrumb, then after I had tests, moved inside and it still worked. It seems a bit odd, to have that inside Breadcrumb, but its only accessible inside Breadcrumb so I guess that is good.
describeBreadcrumbdodescribe'#new'doit'sets default crumb of Home /'do@breadcrumb=Breadcrumb.email@example.com(1).firstname.lastname@example.org=='Homeemail@example.com=='/'endit'sets initial crumb of Main /main'do@breadcrumb=Breadcrumb.new('Main','/main')@breadcrumb.shouldhave(1).firstname.lastname@example.org=='Mainemail@example.com=='/main'endenddescribe'#add'doit'a second crumb'do@breadcrumb=Breadcrumb.firstname.lastname@example.org('Products','/products')@breadcrumb.shouldhave(2).crumbsendend
output of spec doc
Breadcrumb#newsetsdefaultcrumbofHome/setsinitialcrumbofMain/main #add a second crumb