Methods by Reference
Unfortunately, this price
method isn’t great. If you remember from before, we ran into problems when we moved the Fruit
value into the price_fruit
function. When you have a parameter named self
, it means “move it into this method.” Fortunately, methods work with references as well.
Exercise Change self
to &self
and make sure your program still compiles and works.
Get hands-on with 1200+ tech skills courses.