Equivalent scrapbook

…scrap on Files ror

Dir[File.dirname(FILE)+"/support/*/.rb"].each {|f| p require f}

rename file

Dir.glob(folder_path + "/*").sort.each do |f|
  File.rename(f, folder_path + "/" + filename.capitalize + File.extname(f))
end

root

 Rails.root.to_s.

reading and writing to from file

        content =  normal_users.last.to_json

       json_file =  File.open(target, "w") do |f|
          f.write(content)
        end
       json_file.close
   target = "#{Rails.root.to_s}/tmp/old_database_migration.json" 

      data = ''
      f = File.open(target, "r") 
      f.each_line do |line|
        data += line
      end
      f.close

      p data

load all files in folder (best practice)

sinatra

Dir[File.dirname(__FILE__) + '/plugins/index_partials/*.rb'].each {|file| require file }

Dir[Rails.root.to_s + '/app/models/**/*.rb'].each {|file| require file }

rails

    Dir[File.dirname( ::Rails.root.to_s) + '/app/models'].each {|file| print file }

removing folder/files

require 'fileutils'

  FileUtils.rm_rf 'foldername'
  FileUtils.mkdir 'foldername'

file, directory exist ?

          File.directory?('path/to/something')