Ruby/Zmienne globalne: Różnice pomiędzy wersjami
Usunięta treść Dodana treść
Szymon wro (dyskusja | edycje) |
Szymon wro (dyskusja | edycje) |
||
Linia 28:
Istnieje zbiór specjalnych zmiennych, który nazwy składają się ze znaku dolara ($) oraz jakiegoś pojedynczego znaku. Dla przykładu, <tt>$$</tt>. zawiera identyfikator procesu interpretera Rubiego, i jest tylko do odczytu. Oto główne zmienne systemowe:
{| class="wikitable"
$! latest error message▼
! Nazwa
$@ location of error▼
! Opis
$_ string last read by gets▼
|-
$. line number last read by interpreter▼
| $!
$& string last matched by regexp▼
$~ the last regexp match, as an array of subexpressions▼
|-
$n the nth subexpression in the last match (same as $~[n])▼
| $@
$= case-insensitivity flag▼
$/ input record separator▼
|-
$\ output record separator▼
| $_
$0 the name of the ruby script file▼
$* the command line arguments▼
|-
$$ interpreter's process ID▼
| $.
$? exit status of last executed child process▼
|-
| $&
|-
| $~
|-
| $n
|-
| $=
|-
| $/
|-
| $\
|-
|$0
|-
|$*
|-
|$$
|-
|$?
|}
In the above, $_ and $~ have local scope. Their names suggest they should be global, but they are much more useful this way, and there are historical reasons for using these names.
|