Ruby/Zmienne instancji: Różnice pomiędzy wersjami

Usunięta treść Dodana treść
Szymon wro (dyskusja | edycje)
Nie podano opisu zmian
Szymon wro (dyskusja | edycje)
mNie podano opisu zmian
Linia 7:
<pre>
ruby> class InstTest
| def set_fooustaw_a(n)
| @fooa = n
| end
| def set_barustaw_b(n)
| @barb = n
| end
| end
Linia 17:
ruby> i = InstTest.new
#<InstTest:0x83678>
ruby> i.set_fooustaw_a(2)
2
ruby> i
#<InstTest:0x83678 @fooa=2>
ruby> i.set_barustaw_b(4)
4
ruby> i
#<InstTest:0x83678 @fooa=2, @barb=4>
</pre>
 
Zauważ, że powyższe <tt>i</tt> nie zwraca wartości <tt>@barb</tt> dopóki nie zostanie wywołana metoda <tt>set_barustaw_b</tt>.
<noinclude>
{{ProstaNawigacja|spis=Ruby|poprzart=Ruby/Zmienne globalne|poprz=Zmienne globalne|nastart=Ruby/Zmienne lokalne|nast=Zmienne lokalne}}