Реклама

Ruby – modules

Modules in ruby are similar to classes, except: A module can have no instances. A module can have no subclasses. A module is defined by module … end Actually… the Module class of module is the superclass of the Class class of class. Got that? No? Let’s move on. There are two typical uses of modules.…

(Русский) Qt Сертификация

Sorry, this entry is only available in Russian. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language. Ещё с 2009 года было возможно сдать экзамен на Qt сертификацию и стать Сертифицированным Qt разработчиком или Qt специалистом. Сейчас экзамены и…
Advertisement

(Русский) День рождения сайта – 1 Год

Sorry, this entry is only available in Russian. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language. Сегодня 28 июня, а значит сегодня “День Рождения сайта EVILEG”. Год назад был зарегистрирован домен и сделана первая запись в блоге. И…

Ruby – Singleton methods

The behavior of an instance is determined by its class, but there may be times we know that a particular instance should have special behavior. In most languages, we must go to the trouble of defining another class, which would then only be instantiated once. In ruby we can give any object its own methods.…

Ruby – access control

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 define a method in the “top level”, not inside a class definition. We can think of such a method as analogous to a function…

Ruby – Redefinition of methods

In a subclass, we can change the behavior of the instances by redefining superclass methods. Suppose we would rather enhance the superclass’s identifity method than entirely replace it. For this we can use super. super lets us pass arguments to the original method. It is sometimes said that there are two kinds of people…

Ruby – Inheritance

Our classification of objects in everyday life is naturally hierarchical. We know that all cats are mammals, and all mammals are animals. Smaller classes inherit characteristics from the larger classes to which they belong. If all mammals breathe, then all cats breathe. We can express this concept in ruby: Though we didn’t specify how a Cat should…

Ruby – classes

The real world is filled by objects, and we can classify them. For example, a very small child is likely to say “bow-wow” when seeing a dog, regardless of the breed; we naturally see the world in terms of these categories. In OO programming terminology, a category of objects like “dog” is called a class,…

Ruby – methods

What is a method? In OO programming, we don’t think of operating on data directly from outside an object; rather, objects have some understanding of how to operate on themselves (when asked nicely to do so). You might say we pass messages to an object, and those messages will generally elicit some kind of an…

Ruby – Object-oriented thinking

Object oriented is a catchy phrase. To call anything object oriented can make you sound pretty smart. Ruby claims to be an object oriented scripting language; but what exactly does “object oriented” mean? There have been a variety of answers to that question, all of which probably boil down to about the same thing. Rather…