A real variable starts with @ and Its range is limited to the self object. two different objects can have real variables with different values even if they belong to the same class. from outside the object, real variables cannot be changed or even observed (for example, Ruby's real variables are never public), unless the Method ProgramLike a global variable, the value of the real variable before the initialization is nil.
Ruby real variables do not need to be declared. This implies the elastic Structure of the object. In fact, every real variable is dynamically added to the object when it first appears.
Ruby> class insttest
| Def set_foo (N)
| @ Foo = N
| End
| Def set_bar (N)
| @ Bar = N
| End
| End
Nil
Ruby> I = insttest. New
# <Insttest: 0x83678>
Ruby> I. set_foo (2)
2
Ruby> I
# <Insttest: 0x83678 @ Foo = 2>
Ruby> I. set_bar (4)
4
Ruby> I
# <Insttest: 0x83678 @ Foo = 2, @ bar = 4>
Note that the value of @ bar is not reported until the set_bar method I is called in the previous example.