Skip to content

assume native ordered hashes; drop legacy Ordering module (v9.0.0)#30

Open
ahoward wants to merge 1 commit into
masterfrom
drop-legacy-ordering
Open

assume native ordered hashes; drop legacy Ordering module (v9.0.0)#30
ahoward wants to merge 1 commit into
masterfrom
drop-legacy-ordering

Conversation

@ahoward

@ahoward ahoward commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Ruby 1.9+ preserves Hash insertion order natively, and map already requires Ruby >= 3.0. So the manual @keys bookkeeping (recently extracted to Map::Ordering for the dead Ruby-<1.9 path) is pure dead weight. This removes it and lets Map ride Hash's native ordering.

changes

  • delete lib/map/ordering.rb — the @keys array plus the allocate / []= / keys / each* / delete / shift / unshift / push / pop overrides, and its conditional include.
  • promote the native implementations that were guarded by unless RUBY_VERSION < '1.9' || ENV['MAP_FORCE_ORDERING'] to unconditional defs.
  • drop the MAP_FORCE_ORDERING knob and the test:with_ordering / test:without_ordering rake tasks (no second path left).
  • scrub the stale "moved to Map::Ordering" comments.
  • v8.0.0 → v9.0.0 (removes a module + an env knob).

Net: lib/map.rb −65 lines, ordering.rb −126, Rakefile −18.

behavior

No change on any supported Ruby — order flows from Hash#keys/#each everywhere (==, <=>, to_hash, all iterators). One documented note: push of an already-present key now keeps its position (native []=) instead of moving it to the end as the legacy @keys path did. Untested either way; native is now canonical.

tests

ruby -w -I ./lib -I ./test/lib test/map_test.rb56 tests, 4940 assertions, 100% passed.

Version bump to 9.0.0 is a proposal — drop to 8.1.0 if you'd rather treat this as internal-only.

🤖 Generated with Claude Code

Ruby 1.9+ preserves Hash insertion order natively, and the gem already requires
Ruby >= 3.0 — so the manual @keys bookkeeping is dead weight. Remove it:

- delete lib/map/ordering.rb (the @keys array + allocate/[]=/keys/each/delete/
  shift/unshift/push/pop overrides) and its conditional include
- promote the native-Hash implementations (previously guarded by
  `unless RUBY_VERSION < '1.9' || ENV['MAP_FORCE_ORDERING']`) to unconditional defs
- drop the MAP_FORCE_ORDERING env knob and the test:with/without_ordering rake tasks
- scrub the stale "moved to Map::Ordering" comments

No behavior change on any supported Ruby: order flows from Hash#keys/#each
everywhere (==, <=>, to_hash, iterators). One documented note: `push` of an
existing key keeps its position (native []=), rather than moving it to the end as
the legacy @keys path did — untested either way; native is now canonical.

test/map_test.rb: 56 tests, 4940 assertions, 100% green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant