LoginSignup
7
4

More than 3 years have passed since last update.

rake

Posted at

rake

rake は make や ant の ruby版である. ちょっとした作業やよく使う作業をさせる時に便利なように作られている.

例として以下のように記述してみる

task :default do
  system 'rake -T'
  exit
end

desc 'hello NAME'
task :hello do
  name = ARGV[1]
  puts "Hello #{name}!"
  exit
end
> rake

とすると Rakefile が用意している task (仕事) が表示される.

rake hell # hello NAME

次によく使う git pull や git push を追加してみる

git pull

desc 'git pull'
task :pull do
  p comm = "git pull origin main"
  system comm
  exit
end

git push

desc 'git push'
task :push do
  p comm = "git add -A"
  system comm
  comm = "git commit -m 'hoge'"
  puts comm.green
  system comm
  p comm = "git pull origin main"
  system comm
  p comm = "git push origin main"
  system comm
  exit
end

これで

> rake push

とするだけで github 共有をできるようになった

おまけ

私は screenshot をよく使うので, screenshot の Rakefile を作成してみた

desc 'screenshot'
task :screenshot do
  p comm = "gnome-screenshot --area"
  system comm
  exit
end

これは area を指定してその部分を .pngファイルで保存するというものだ.

参考ページ

チャート式ruby-appendix-IV(rake)


  • source ~/grad_members_20f/members/djj31370/rake.org
7
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4