Skip to content

Instantly share code, notes, and snippets.

@AntelopeSalad
Last active August 29, 2015 14:03
Show Gist options
  • Save AntelopeSalad/534c37f216da9e1a22cb to your computer and use it in GitHub Desktop.
Save AntelopeSalad/534c37f216da9e1a22cb to your computer and use it in GitHub Desktop.
Which is more idiomatic ruby?
path = '/home/you/foo/bar/baz'
# assume this path has a folder called hello and a file within the hello folder
Dir[File.join(path, '**', '*')].each do |file|
puts file.split(path)
# => hello/world.rb
end
# vs.
Dir[File.join(path, '**', '*')].each do |file|
puts file.sub(path, '')
# => hello/world.rb
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment