From 0f80544e9cd40ba165581a29472f44fa94451f8b Mon Sep 17 00:00:00 2001 From: ADTC Date: Wed, 7 Jul 2021 19:18:19 +0800 Subject: [PATCH] Add example in docs for making arrays without keys This was only discussed in issue #104 but not mentioned anywhere else. --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index e3655e62..1006737e 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,16 @@ json.array! @people, :id, :name # => [ { "id": 1, "name": "David" }, { "id": 2, "name": "Jamie" } ] ``` +To make a plain array without keys, construct and pass in a standard Ruby array. + +``` ruby +my_array = %w(David Jamie) + +json.people my_array + +# => "people": [ "David", "Jamie" ] +``` + Jbuilder objects can be directly nested inside each other. Useful for composing objects. ``` ruby