Skip to content

Commit e677dd8

Browse files
ADTCdhh
andauthored
Add example in docs for making arrays without keys (#506)
This was only discussed in issue #104 but not mentioned anywhere else. Co-authored-by: David Heinemeier Hansson <[email protected]>
1 parent 83c3c96 commit e677dd8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ json.array! @people, :id, :name
108108
# => [ { "id": 1, "name": "David" }, { "id": 2, "name": "Jamie" } ]
109109
```
110110

111+
To make a plain array without keys, construct and pass in a standard Ruby array.
112+
113+
``` ruby
114+
my_array = %w(David Jamie)
115+
116+
json.people my_array
117+
118+
# => "people": [ "David", "Jamie" ]
119+
111120
You don't always have or need a collection when building an array.
112121
113122
```ruby

0 commit comments

Comments
 (0)