Ruby/Inicjalizacja obiektów: Różnice pomiędzy wersjami
Usunięta treść Dodana treść
m nav |
Szymon wro (dyskusja | edycje) Nie podano opisu zmian |
||
Linia 1:
== Inicjalizacja obiektów ==
Nasza klasa <tt>Fruit</tt> z [[Ruby/Akcesory|poprzedniego rozdziału]] ma dwie zmienne instancji, jedną by opisywać rodzaj owocu,
Our Fruit class from the previous chapter had two instance variables, one to describe the kind of fruit and another to describe its condition. It was only after writing a custom inspect method for the class that we realized it didn't make sense for a piece of fruit to lack those characteristics. Fortunately, ruby provides a way to ensure that instance variables always get initialized.
The initialize method
|