Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions lib/jbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def initialize(
end

# Yields a builder and automatically turns the result into a JSON string
def self.encode(*args, &block)
new(*args, &block).target!
def self.encode(...)
new(...).target!
end

BLANK = Blank.new
Expand Down
7 changes: 7 additions & 0 deletions test/jbuilder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -936,4 +936,11 @@ class JbuilderTest < ActiveSupport::TestCase
result = JSON.load(Jbuilder.encode { |json| json.time Time.parse("2018-05-13 11:51:00.485 -0400") })
assert_equal "2018-05-13T11:51:00.485-04:00", result["time"]
end

test "encode forwards options to new" do
Jbuilder.encode(key_formatter: 1, ignore_nil: 2) do |json|
assert_equal 1, json.instance_eval{ @key_formatter }
assert_equal 2, json.instance_eval{ @ignore_nil }
end
end
end