Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/jbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,16 @@ def target!

alias_method :method_missing, :set!

def _set(key, value = BLANK, attributes = nil)
result = if ::Kernel.block_given?
def _set(key, value = BLANK, attributes = nil, &block)
result = if block
if _blank?(value)
# json.comments { ... }
# { "comments": ... }
_merge_block(key) { yield self }
_merge_block key, &block
else
# json.comments @post.comments { |comment| ... }
# { "comments": [ { ... }, { ... } ] }
_scope { _array(value) { |element| yield element } }
_scope { _array value, &block }
end
elsif attributes.blank?
if ::Jbuilder === value
Expand Down