Variáveis globais especiais

Como sempre esqueço o que é cada tipo de variável global especial, resolvi colocar na minha memória para sempre!

$! latest error message
$@ location of error
$_ 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

;)

Referência: Ruby User’s Guide – Global variables


3 Comentários on “Variáveis globais especiais”

  1. >> ” foo bar baz” =~ /bar/
    => 5
    >> $` #pre match
    => ” foo ”
    >> $’ #pos match
    => ” baz”
    >> $& #o match
    => “bar”

    • Celestino Gomes disse:

      @shairon, como sempre colaborando, valeu!

  2. Sempre bom relembrar e ter uma referência online pra consultar! ;)

Seguir

Obtenha todo post novo entregue na sua caixa de entrada.

Join 602 other followers