Skip to content

Instantly share code, notes, and snippets.

@moonmaster9000
Created April 11, 2010 22:02
Show Gist options
  • Save moonmaster9000/363103 to your computer and use it in GitHub Desktop.
Save moonmaster9000/363103 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# applies a transform_function (Proc instance) to an input_file
# and writes it out to the output_file
def transform_file(transformer_function, input_file, output_file)
File.open(output_file, 'w') do |f|
f.write transformer_function.call(File.read(input_file))
end
end
# returns a proc that splits a newline on either
# Windows or Unix-style line endings, then joins
# them with Unix-style line endings
def unix_newlines
lambda {|f| f.split.join("\n")}
end
if ARGV.length != 2
raise(
StandardError,
"You must provide two file names on the command line!"
)
else
transform_file unix_newlines, ARGV.first, ARGV.last
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment