Início > ruby > Variáveis globais especiais

Variáveis globais especiais

29/06/2009


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

Categoriasruby Tags:,
  1. 29/06/2009 às 15:49 | #1

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

    • Celestino Gomes
      29/06/2009 às 17:15 | #2

      @shairon, como sempre colaborando, valeu!

  2. 01/07/2009 às 05:24 | #3

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

Fechado para comentários.