Arquivo

Archive for junho, 2009

Variáveis globais especiais

29/06/2009 3 comentários

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:,

rake com argumentos

15/06/2009 3 comentários
desc "Say hi. Use USER environment variable as default"
  task :hi, :user do |t, args|
  args.with_defaults(:user => ENV["USER"])

  puts "Hi #{args[:user]}!"
end

Código disponível em http://gist.github.com/130194

logo:

celestino@macbook:~
$ echo $USER
celestino

celestino@macbook:~ $ rake hi
(in /Users/celestino)
Hi celestino!

celestino@macbook:~ $ USER=tino rake hi
(in /Users/celestino)
Hi tino!

celestino@macbook:~ $ rake hi USER=tino2
(in /Users/celestino)
Hi tino2!

celestino@macbook:~ $ rake hi[tino3]
(in /Users/celestino)
Hi tino3!

Fonte: http://nhw.pl/wp/2008/10/11/rake-and-arguments-for-tasks

Categoriasruby, tutorial Tags:,