Module: JSON::Ext
| Relationships & Source Files | |
| Namespace Children | |
|
Modules:
| |
|
Classes:
| |
| Defined in: | ext/json/lib/json/ext.rb, ext/json/generator/generator.c, ext/json/lib/json/ext/generator/state.rb, ext/json/parser/parser.c |
Overview
This module holds all the modules/classes that implement JSON's functionality as C extensions.
Class Method Summary
- .on_duplicate_key(hash, as_json)
- .coerce_key(key, as_json) Internal use only
-
.shareable_lambda(block)
Internal use only
See additional method definition at line 33.
- .valid_encoding?(str) ⇒ Boolean Internal use only
Class Method Details
.coerce_key(key, as_json)
This method is for internal use only.
[ GitHub ]
# File 'ext/json/lib/json/ext.rb', line 46
def coerce_key(key, as_json) # :nodoc: as_json_called = false unless String === key || Symbol === key key = as_json.call(key, true) as_json_called = true end if Symbol === key key = key.to_s end unless String === key raise GeneratorError.new("#{key.class} not allowed as object key in JSON", key) end unless valid_encoding?(key) if as_json_called raise GeneratorError.new("source sequence is illegal/malformed utf-8", key) end key = as_json.call(key, true) unless String === key raise GeneratorError.new("#{key.class} not allowed as object key in JSON", key) end unless Ext.valid_encoding?(key) raise GeneratorError.new("source sequence is illegal/malformed utf-8", key) end end key end
.on_duplicate_key(hash, as_json)
[ GitHub ]# File 'ext/json/lib/json/ext.rb', line 80
def on_duplicate_key(hash, as_json) set = {} hash.each_key do |key| key = coerce_key(key, as_json) if set[key] raise GeneratorError.new("detected duplicate key #{key.inspect}", key) else set[key] = true end end end
.valid_encoding?(str) ⇒ Boolean
This method is for internal use only.
# File 'ext/json/lib/json/ext.rb', line 42
def valid_encoding?(str) # :nodoc: str.ascii_only? || (str.encoding == Encoding::UTF_8 && str.valid_encoding?) end