Skip to content

Commit

Permalink
[rubocop#184 rubocop#222] Acknowledge double-quoted strings as good s…
Browse files Browse the repository at this point in the history
…tyle
  • Loading branch information
Bozhidar Batsov committed Feb 18, 2014
1 parent 5d91665 commit d78c40c
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2391,16 +2391,34 @@ hash rockets syntax.
"#{ user.last_name }, #{ user.first_name }"
```

* Prefer single-quoted strings when you don't need string interpolation or
special symbols such as `\t`, `\n`, `'`, etc.
* Adopt a consistent string literal quoting style. There are two
popular styles in the Ruby community, both of which are considered
good - single quotes by default and double quotes by default.

```Ruby
# bad
name = "Bozhidar"
* Prefer single-quoted strings when you don't need string interpolation or
special symbols such as `\t`, `\n`, `'`, etc.
# good
name = 'Bozhidar'
```
```Ruby
# bad
name = "Bozhidar"

# good
name = 'Bozhidar'
```

* Prefer double-quotes unless your string literal contains `"` or escape characters you want to suppress.

```Ruby
# bad
name = 'Bozhidar'
# good
name = "Bozhidar"
```

The second style is arguably a bit more popular in the Ruby
community. The string literals in the this guide, however, are
aligned with the first style.

* Don't use the character literal syntax `?x`. Since Ruby 1.9 it's
basically redundant - `?x` would interpreted as `'x'` (a string with
Expand Down

0 comments on commit d78c40c

Please sign in to comment.