Skip to main content
deleted 11 characters in body
Source Link
Chris
  • 4.4k
  • 1
  • 7
  • 36

Only a few notes:

  • Creating dir_paths as an empty array, then on the next line immediately appending projects_path to it seems odd vs. just adding it immediately.
  • dir_paths[1...(dir_paths.length)] is equivalent to dir_paths[1..-1]

With these changes:

require "date"
require "fileutils"

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

if Dir.exist? projects_path
  puts "#{projects_path} does already exist.\nExiting."
  exit true
else
  FileUtils.mkdir_p dir_paths
  dir_paths[1..-1].each do |path|
    FileUtils.touch [
      "#{path}/logs.txt",
      "#{path}/notes.txt" ]
  end
  puts "Created directory '#{projects_path}' successfully."
end

Given that if projects_path already exists, the program exits immediately, you could off course elide the else entirely.

require "date"
require "fileutils"

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

if Dir.exist? projects_path
  puts "#{projects_path} does already exist.\nExiting."
  exit true
end
  
FileUtils.mkdir_p dir_paths
dir_paths[1..-1].each do |path|
  FileUtils.touch [
    "#{path}/logs.txt",
    "#{path}/notes.txt" ]
end
puts "Created directory '#{projects_path}' successfully."

It's also possible to distill:

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

Down to the more declarative following code.

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [
  project_paths,
  *["alpha", "beta", "gamma"].map { |name| 
    "#{projects_path"}/team_#{name}" 
  }
]

Only a few notes:

  • Creating dir_paths as an empty array, then on the next line immediately appending projects_path to it seems odd vs. just adding it immediately.
  • dir_paths[1...(dir_paths.length)] is equivalent to dir_paths[1..-1]

With these changes:

require "date"
require "fileutils"

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

if Dir.exist? projects_path
  puts "#{projects_path} does already exist.\nExiting."
  exit true
else
  FileUtils.mkdir_p dir_paths
  dir_paths[1..-1].each do |path|
    FileUtils.touch [
      "#{path}/logs.txt",
      "#{path}/notes.txt" ]
  end
  puts "Created directory '#{projects_path}' successfully."
end

Given that if projects_path already exists, the program exits immediately, you could off course elide the else entirely.

require "date"
require "fileutils"

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

if Dir.exist? projects_path
  puts "#{projects_path} does already exist.\nExiting."
  exit true
end
  
FileUtils.mkdir_p dir_paths
dir_paths[1..-1].each do |path|
  FileUtils.touch [
    "#{path}/logs.txt",
    "#{path}/notes.txt" ]
end
puts "Created directory '#{projects_path}' successfully."

It's also possible to distill:

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

Down to the more declarative following code.

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [
  project_paths,
  *["alpha", "beta", "gamma"].map { |name| 
    "#{projects_path"}/team_#{name}" 
  }
]

Only a few notes:

  • Creating dir_paths as an empty array, then on the next line immediately appending projects_path to it seems odd vs. just adding it immediately.
  • dir_paths[1...(dir_paths.length)] is equivalent to dir_paths[1..-1]

With these changes:

require "date"
require "fileutils"

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

if Dir.exist? projects_path
  puts "#{projects_path} does already exist.\nExiting."
  exit true
else
  FileUtils.mkdir_p dir_paths
  dir_paths[1..-1].each do |path|
    FileUtils.touch [
      "#{path}/logs.txt",
      "#{path}/notes.txt" ]
  end
  puts "Created directory '#{projects_path}' successfully."
end

Given that if projects_path already exists, the program exits immediately, you could elide the else entirely.

require "date"
require "fileutils"

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

if Dir.exist? projects_path
  puts "#{projects_path} does already exist.\nExiting."
  exit true
end
  
FileUtils.mkdir_p dir_paths
dir_paths[1..-1].each do |path|
  FileUtils.touch [
    "#{path}/logs.txt",
    "#{path}/notes.txt" ]
end
puts "Created directory '#{projects_path}' successfully."

It's also possible to distill:

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

Down to the more declarative following code.

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [
  project_paths,
  *["alpha", "beta", "gamma"].map { |name| 
    "#{projects_path"}/team_#{name}" 
  }
]
added 458 characters in body
Source Link
Chris
  • 4.4k
  • 1
  • 7
  • 36

Only a few notes:

  • Creating dir_paths as an empty array, then on the next line immediately appending projects_path to it seems odd vs. just adding it immediately.
  • dir_paths[1...(dir_paths.length)] is equivalent to dir_paths[1..-1]

With these changes:

require "date"
require "fileutils"

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

if Dir.exist? projects_path
  puts "#{projects_path} does already exist.\nExiting."
  exit true
else
  FileUtils.mkdir_p dir_paths
  dir_paths[1..-1].each do |path|
    FileUtils.touch [
      "#{path}/logs.txt",
      "#{path}/notes.txt" ]
  end
  puts "Created directory '#{projects_path}' successfully."
end

Given that if projects_path already exists, the program exits immediately, you could off course elide the else entirely.

require "date"
require "fileutils"

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

if Dir.exist? projects_path
  puts "#{projects_path} does already exist.\nExiting."
  exit true
end
  
FileUtils.mkdir_p dir_paths
dir_paths[1..-1].each do |path|
  FileUtils.touch [
    "#{path}/logs.txt",
    "#{path}/notes.txt" ]
end
puts "Created directory '#{projects_path}' successfully."

It's also possible to distill:

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

Down to the more declarative following code.

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [
  project_paths,
  *["alpha", "beta", "gamma"].map { |name| 
    "#{projects_path"}/team_#{name}" 
  }
]

Only a few notes:

  • Creating dir_paths as an empty array, then on the next line immediately appending projects_path to it seems odd vs. just adding it immediately.
  • dir_paths[1...(dir_paths.length)] is equivalent to dir_paths[1..-1]

With these changes:

require "date"
require "fileutils"

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

if Dir.exist? projects_path
  puts "#{projects_path} does already exist.\nExiting."
  exit true
else
  FileUtils.mkdir_p dir_paths
  dir_paths[1..-1].each do |path|
    FileUtils.touch [
      "#{path}/logs.txt",
      "#{path}/notes.txt" ]
  end
  puts "Created directory '#{projects_path}' successfully."
end

Given that if projects_path already exists, the program exits immediately, you could off course elide the else entirely.

require "date"
require "fileutils"

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

if Dir.exist? projects_path
  puts "#{projects_path} does already exist.\nExiting."
  exit true
end
  
FileUtils.mkdir_p dir_paths
dir_paths[1..-1].each do |path|
  FileUtils.touch [
    "#{path}/logs.txt",
    "#{path}/notes.txt" ]
end
puts "Created directory '#{projects_path}' successfully."

Only a few notes:

  • Creating dir_paths as an empty array, then on the next line immediately appending projects_path to it seems odd vs. just adding it immediately.
  • dir_paths[1...(dir_paths.length)] is equivalent to dir_paths[1..-1]

With these changes:

require "date"
require "fileutils"

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

if Dir.exist? projects_path
  puts "#{projects_path} does already exist.\nExiting."
  exit true
else
  FileUtils.mkdir_p dir_paths
  dir_paths[1..-1].each do |path|
    FileUtils.touch [
      "#{path}/logs.txt",
      "#{path}/notes.txt" ]
  end
  puts "Created directory '#{projects_path}' successfully."
end

Given that if projects_path already exists, the program exits immediately, you could off course elide the else entirely.

require "date"
require "fileutils"

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

if Dir.exist? projects_path
  puts "#{projects_path} does already exist.\nExiting."
  exit true
end
  
FileUtils.mkdir_p dir_paths
dir_paths[1..-1].each do |path|
  FileUtils.touch [
    "#{path}/logs.txt",
    "#{path}/notes.txt" ]
end
puts "Created directory '#{projects_path}' successfully."

It's also possible to distill:

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

Down to the more declarative following code.

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [
  project_paths,
  *["alpha", "beta", "gamma"].map { |name| 
    "#{projects_path"}/team_#{name}" 
  }
]
Source Link
Chris
  • 4.4k
  • 1
  • 7
  • 36

Only a few notes:

  • Creating dir_paths as an empty array, then on the next line immediately appending projects_path to it seems odd vs. just adding it immediately.
  • dir_paths[1...(dir_paths.length)] is equivalent to dir_paths[1..-1]

With these changes:

require "date"
require "fileutils"

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

if Dir.exist? projects_path
  puts "#{projects_path} does already exist.\nExiting."
  exit true
else
  FileUtils.mkdir_p dir_paths
  dir_paths[1..-1].each do |path|
    FileUtils.touch [
      "#{path}/logs.txt",
      "#{path}/notes.txt" ]
  end
  puts "Created directory '#{projects_path}' successfully."
end

Given that if projects_path already exists, the program exits immediately, you could off course elide the else entirely.

require "date"
require "fileutils"

projects_path = "./reports/#{Time.now.strftime("%Y_%m_%d_%H_%M")}"
dir_paths = [project_paths]

["alpha", "beta", "gamma"].each do |name|
  dir_paths << "#{projects_path}/team_#{name}"
end

if Dir.exist? projects_path
  puts "#{projects_path} does already exist.\nExiting."
  exit true
end
  
FileUtils.mkdir_p dir_paths
dir_paths[1..-1].each do |path|
  FileUtils.touch [
    "#{path}/logs.txt",
    "#{path}/notes.txt" ]
end
puts "Created directory '#{projects_path}' successfully."