require "active_support/core_ext" def build_json(n) struct = Struct.new(:name, :birthyear, :bio, :url) author = struct.new("Rolf", 1920, "Software developer", "http://example.com/") author.instance_eval { undef each } # Jbuilder doesn't like #each on non-arrays. now = Time.now arr = 100.times.to_a n.times do json = Jbuilder.encode do |json| json.article do |json| json.author(author, :name, :birthyear, :bio) json.title "Profiling Jbuilder" json.body "How to profile Jbuilder" json.date now json.references arr do |json, ref| json.name "Introduction to profiling" json.url "http://example.com/" end json.comments arr do |json, comment| json.author(author, :name, :birthyear, :bio) json.email "rolf@example.com" json.body "Great article" json.date now end end end end end