Skip to content

Instantly share code, notes, and snippets.

@thash
Last active August 29, 2015 13:56
Show Gist options
  • Save thash/a86b9799ae60eb1deec6 to your computer and use it in GitHub Desktop.
Save thash/a86b9799ae60eb1deec6 to your computer and use it in GitHub Desktop.
task :goodbye, [:name, :alias] do |t, args|
puts "Goodbye, #{args.name} the #{args.alias}!"
end
task :default => :hello
task :default => :hello
desc '挨拶をします'
task :hello do
puts "Hello!"
end
desc '名前とニックネームを引数にとり、別れの挨拶をします'
task :goodbye, [:name, :nickname] do |t, args|
puts "Goodbye, #{args.name} the #{args.nickname}!"
end
namespace :math do
desc '二乗を計算します'
task :square, [:n] do |t, args|
n = args.n.to_i
puts n * n
end
desc '三乗を計算します'
task :cube, [:n] do |t, args|
n = args.n.to_i
puts n * n * n
end
end
directory 'hoge/fuga/piyo'
$ rake "goodbye[Rake, greeter]"
Goodbye, Rake the greeter!
$ rake
Hello!
$ rake -T
rake goodbye[name,nickname] # 名前とニックネームを引数にとり、別れの挨拶をします
rake hello # 挨拶をします
rake math:cube[n] # 三乗を計算します
rake math:square[n] # 二乗を計算します
$ rake hoge/fuga/piyo
mkdir -p hoge/fuga/piyo
$ ls
Rakefile
$ rake hoge.txt
writing hoge.txt
$ ls
Rakefile hoge.txt
$ cat hoge.txt
texttext
$ rake hoge.txt # 何も起こらない
$ rake hello
Hello!
$ rake "math:square[2]"
4
$ rake "math:cube[2]"
8
file 'hoge.txt' do
puts 'writing hoge.txt'
open('./hoge.txt', 'w'){|f| f.write 'texttext' }
end
task :hello do
puts 'Hello!'
end
$ gem install rake
rake's executable "rake" conflicts with /Users/hash/.rbenv/versions/2.0.0-p353/bin/rake
Overwrite the executable? [yN] y
Successfully installed rake-10.1.1
1 gem installed
$ rake --version
rake, version 10.1.1
namespace :math do
task :square, [:n] do |t, args|
n = args.n.to_i
puts n * n
end
task :cube, [:n] do |t, args|
n = args.n.to_i
puts n * n * n
end
end
$ rake
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
(See full trace by running task with --trace)
$ ruby fork.rb
$ ps aux | grep "[r]uby" # (別ターミナルで)
hash 45929 0.0 0.0 2457176 456 s001 S 8:33AM 0:00.00 ruby fork.rb
hash 45928 0.0 0.0 2457176 456 s001 S 8:33AM 0:00.00 ruby fork.rb
hash 45927 0.0 0.0 2457176 456 s001 S 8:33AM 0:00.00 ruby fork.rb
hash 45926 0.0 0.0 2457176 456 s001 S 8:33AM 0:00.00 ruby fork.rb
hash 45925 0.0 0.0 2457176 456 s001 S 8:33AM 0:00.00 ruby fork.rb
hash 45924 0.0 0.0 2457176 456 s001 S 8:33AM 0:00.00 ruby fork.rb
hash 45923 0.0 0.0 2457176 456 s001 S 8:33AM 0:00.00 ruby fork.rb
hash 45922 0.0 0.0 2457176 456 s001 S 8:33AM 0:00.00 ruby fork.rb
hash 45921 0.0 0.0 2457176 456 s001 S 8:33AM 0:00.00 ruby fork.rb
hash 45920 0.0 0.0 2457176 456 s001 S 8:33AM 0:00.00 ruby fork.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment