module Prawn::SVG::Elements::CallDuplicator
Unfortunately, prawn mutates arguments passed in to it. When we make a copy of one of the call stacks, we need to make a deep duplicate of it so that the first time prawn mutates the arguments, it won't affect the subsequent calls.
Private Instance Methods
duplicate_array(array)
click to toggle source
# File lib/prawn/svg/elements/call_duplicator.rb, line 18 def duplicate_array(array) array.map do |value| case value when Array then duplicate_array(value) when Hash then duplicate_hash(value) else value end end end
duplicate_call(call)
click to toggle source
# File lib/prawn/svg/elements/call_duplicator.rb, line 14 def duplicate_call(call) [call[0], duplicate_array(call[1]), duplicate_calls(call[2])] end
duplicate_calls(calls)
click to toggle source
# File lib/prawn/svg/elements/call_duplicator.rb, line 10 def duplicate_calls(calls) calls.map { |call| duplicate_call(call) } end
duplicate_hash(hash)
click to toggle source
# File lib/prawn/svg/elements/call_duplicator.rb, line 28 def duplicate_hash(hash) hash.each.with_object({}) do |(key, value), result| result[key] = case value when Array then duplicate_array(value) when Hash then duplicate_hash(value) else value end end end