Last active
August 29, 2015 14:03
-
-
Save AntelopeSalad/534c37f216da9e1a22cb to your computer and use it in GitHub Desktop.
Which is more idiomatic ruby?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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