-
-
Notifications
You must be signed in to change notification settings - Fork 261
Open
Description
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).
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 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 thatOpenStructis patched as a default). Note: ifOpenStructis passed as an argument, there is no need to require it. - ... because
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::GenericObjectis- 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; torequire "json/generic_object"directly works immediately), and - the code of
generic_object.rbcalls nothing but methods fromJSON, which are mimicked byOj(AFAICS).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels