タグ

fileとeachに関するkiyo_hikoのブックマーク (1)

  • Iterate through every file in one directory

    How do I write a loop in ruby so that I can execute a block of code on each file? I'm new to ruby, and I've concluded that the way to do this is a do each loop. The ruby file will be executed from a different directory than the directory I want to loop through. I've tried the Dir.foreach and I couldn't get it to work.

    Iterate through every file in one directory
    kiyo_hiko
    kiyo_hiko 2016/04/18
    とりあえずPadrinoプロジェクトでRACK_ENVによってrake db:seedのうごき切り替えるのにつかった。こんな感じになった → path = File.join(Padrino.root, *%w(db seeds), Padrino.env.to_s, '*.rb'); Dir.glob path do |f|; require f; end
  • 1