SOA_Homework
require 'yaml'
students = YAML::load(File.read(ARGV[0]))
keys = students[0].keys
content = students.map { |student| student.values.join("\t") }.join("\n")
if ARGV[1]
File.open(ARGV[1], 'w') do |file|
file.puts keys.join("\t")
file.puts content
end
else
puts keys.join("\t")
puts content
end
require 'yaml'
in_lines = File.read(ARGV[0]).split("\n")
keys = in_lines[0].split("\t")
students = []
in_lines[1..-1].each do |line|
data = line.split("\t")
hash = {}
data.each.with_index { |d, i| hash[keys[i]] = d }
students << hash
end
if ARGV[1]
File.open(ARGV[1], 'w') { |file| file.puts students.to_yaml }
else
puts students.to_yaml
end
def fizzbuzz(size, &strategy)
arr = []
(1..size).each do |i|
s = ''
s += 'Fizz' if i % 3 == 0
s += 'Buzz' if i % 5 == 0
if s.empty? then arr << i else arr << s end
if strategy
if s.empty? then yield i else yield s end
end
end
arr
end