Variáveis globais especiais
Publicado; 29/06/2009 Filed under: ruby | Tags: ruby, variável global 3 Comments »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
rake com argumentos
Publicado; 15/06/2009 Filed under: ruby, tutorial | Tags: rake, ruby 3 Comments »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





