Ruby's core makes some effort to squeeze ostruct / OpenStruct out of the code. The gem 'json', promoted to a default gem now, is no exception to this. Any require "ostruct" there has been transformed into conditional code (see MRI 3.3 => 3.4).
OpenStruct itself is monkey-patched only with an active require 'json/add/ostruct' (see e.g. https://rubyapi.org/3.4/o/openstruct)
JSON::GenericObject is only an autoload. Which works even if require 'ostruct' would raise a LoadError.
Best if Oj would be able to drop s.add_runtime_dependency 'ostruct', '>= 0.2'. And run any require 'ostruct' only if "actively demanded" ...
- ... by
Oj.add_to_json() (if this continues to promise that OpenStruct is patched as a default). Note: if OpenStruct is passed as an argument, there is no need to require it.
- ... because
JSON::GenericObject is (auto-)loaded. Could even be, that Oj doesn't need to define JSON::GenericObject at all anymore (for a modern Ruby). AFAICS, the default json gem's JSON::GenericObject is
- unconditionally available (at least for the lowest MRI version supported (RBX might be different): https://github.com/ruby/ruby/blob/ruby_2_4/ext/json/lib/json/generic_object.rb)
- "demands" only an autoload declaration (which is set up by json gem's
require "json", i.e. Oj would have to declare something similar; to require "json/generic_object" directly works immediately), and
- the code of
generic_object.rb calls nothing but methods from JSON, which are mimicked by Oj (AFAICS).
Ruby's core makes some effort to squeeze
ostruct/OpenStructout of the code. The gem 'json', promoted to a default gem now, is no exception to this. Anyrequire "ostruct"there has been transformed into conditional code (see MRI 3.3 => 3.4).OpenStructitself is monkey-patched only with an activerequire 'json/add/ostruct'(see e.g. https://rubyapi.org/3.4/o/openstruct)JSON::GenericObjectis only anautoload. Which works even ifrequire 'ostruct'would raise aLoadError.Best if
Ojwould be able to drops.add_runtime_dependency 'ostruct', '>= 0.2'. And run anyrequire 'ostruct'only if "actively demanded" ...Oj.add_to_json()(if this continues to promise thatOpenStructis patched as a default). Note: ifOpenStructis passed as an argument, there is no need to require it.JSON::GenericObjectis (auto-)loaded. Could even be, that Oj doesn't need to defineJSON::GenericObjectat all anymore (for a modern Ruby). AFAICS, the default json gem'sJSON::GenericObjectisrequire "json", i.e. Oj would have to declare something similar; torequire "json/generic_object"directly works immediately), andgeneric_object.rbcalls nothing but methods fromJSON, which are mimicked byOj(AFAICS).