Ruby/Kontrola dostępu: Różnice pomiędzy wersjami

Usunięta treść Dodana treść
Szymon wro (dyskusja | edycje)
Nowa strona: Earlier, we said that ruby has no functions, only methods. However there is more than one kind of method. In this chapter we introduce access controls. Consider what happens when we de...
 
Kj (dyskusja | edycje)
m +nav
Linia 49:
 
We might have expected test.engine(6) to return 12, but instead we learn that engine is inaccessible when we are acting as a user of a Test object. Only other Test methods, such as times_two, are allowed to use engine. We are required to go through the public interface, which consists of the times_two method. The programmer who is in charge of this class can change engine freely (here, perhaps by changing b*2 to b+b, assuming for the sake of argument that it improved performance) without affecting how the user interacts with Test objects. This example is of course much too simple to be useful; the benefits of access controls become more clear only when we begin to create more complicated and interesting classes.
<noinclude>
{{ProstaNawigacja|spis=Ruby|poprzart=Ruby/Redefinicja metod|poprz=Redefinicja metod|nastart=Ruby/Metody singleton|nast=Metody sigleton}}
</noinclude>