Реклама

Ruby – Class constants

A constant has a name starting with an uppercase character. It should be assigned a value at most once. In the current implementation of ruby, reassignment of a constant generates a warning but not an error (the non-ANSI version of eval.rb does not report the warning): Constants may be defined within classes, but unlike instance…

Ruby – Local variables

A local variable has a name starting with a lower case letter or an underscore character (_). Local variables do not, like globals and instance variables, have the value nil before initialization: The first assignment you make to a local variable acts something like a declaration. If you refer to an uninitialized local variable, the ruby interpreter…
Advertisement

Ruby – Instance variables

An instance variable has a name beginning with @, and its scope is confined to whatever object self refers to. Two different objects, even if they belong to the same class, are allowed to have different values for their instance variables. From outside the object, instance variables cannot be altered or even observed (i.e., ruby’s instance variables…

(Русский) Intents с Qt для Android, часть 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. “Intent” является главной возможностью для межпроцессорного взаимодействия в Android. В основном, Intent является объектом, который обрабатывается операционной системой и передаётся затем одному…

Ruby – global variables

A global variable has a name beginning with $. It can be referred to from anywhere in a program. Before initialization, a global variable has the special value nil. Global variables should be used sparingly. They are dangerous because they can be written to from anywhere. Overuse of globals can make isolating bugs difficult; it also tends…

Ruby – variables

Ruby has three kinds of variables, one kind of constant and exactly two pseudo-variables. The variables and the constants have no type. While untyped variables have some drawbacks, they have many more advantages and fit well with ruby’s quick and easy philosophy. Variables must be declared in most languages in order to specify their type,…

Ruby – procedure objects

It is often desirable to be able to specify responses to unexpected events. As it turns out, this is most easily done if we can pass blocks of code as arguments to other methods, which means we want to be able to treat code as if it were data. A new procedure object is formed using…

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.…

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…