Skip to content

Commit 1ec4ecd

Browse files
committed
WIP
1 parent 6140de1 commit 1ec4ecd

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/json/truffle_ruby/generator.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ def configure(opts)
290290
end
291291
alias merge configure
292292

293+
def allow_duplicate_key? # :nodoc:
294+
@allow_duplicate_key
295+
end
296+
293297
# Returns the configuration instance variables as a hash, that can be
294298
# passed to the configure method.
295299
def to_h
@@ -491,9 +495,18 @@ def json_transform(state)
491495
delim = ",#{state.object_nl}"
492496
result = +"{#{state.object_nl}"
493497
first = true
498+
key_type = nil
494499
indent = !state.object_nl.empty?
495500
each { |key, value|
496-
result << delim unless first
501+
if first
502+
key_type = key.class
503+
else
504+
if key_type && !state.allow_duplicate_key? && key_type != key.class
505+
key_type = nil # stop checking
506+
JSON.send(:on_mixed_keys_hash, self, state.allow_duplicate_key? == false)
507+
end
508+
result << delim
509+
end
497510
result << state.indent * depth if indent
498511

499512
if state.strict? && !(Symbol === key || String === key)

0 commit comments

Comments
 (0)