Skip to content

Instantly share code, notes, and snippets.

@danimal141
Created April 10, 2014 08:34
Show Gist options
  • Save danimal141/10356775 to your computer and use it in GitHub Desktop.
Save danimal141/10356775 to your computer and use it in GitHub Desktop.
# Before
def get_file_names path
file_names = []
Dir.glob(path).each do |file|
file_names << File.basename(file) if File::ftype(file) == "file"
end
return file_names
end
# After Refactoring
def get_file_names path
[].tap do |file_names|
Dir.glob(path).each do |file|
file_names << File.basename(file) if File::ftype(file) == 'file'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment