Permalink
Browse files

Simplify the File.join remark.

It's really when using static strings that it's so grossly
unnecessary.
  • Loading branch information...
1 parent 1f092f6 commit 0cf9ab4a1eb663325efaa82b1c376e78f48dc435 @oggy oggy committed Aug 31, 2012
Showing with 7 additions and 10 deletions.
  1. +7 −10 README.md
View
@@ -1494,22 +1494,19 @@ syntax.
* Use `OptionParser` for parsing complex command line options and
`ruby -s` for trivial command line options.
-* Don't use File.join to piece together file names unless:
- * Segments may contain a trailing '/' (usually optional - most file
- operations clean given paths of duplicate slashes)
- * You're displaying the resulting string to a user (required on
- Windows)
-
- ```Ruby
+* Don't use File.join to piece together file names from static strings.
+ ```Ruby
# bad
path = File.join(Rails.root, 'config', 'blah.yml')
- # good
+ # better - works because Rails.root is a Pathname
+ path = Rails.root.join('config/blah.yml')
+
+ # best
path = "#{Rails.root}/config/blah.yml"
```
- (Contrary to popular belief, even if this was actually run on
- Windows, it'd run just fine.)
+ (Contrary to popular belief, this runs just fine on Windows.)
* Code in a functional way, avoiding mutation when that makes sense.
* Avoid needless metaprogramming.

0 comments on commit 0cf9ab4

Please sign in to comment.