Commit f1b5229f

f1b5229f4adfMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified

Description

Implement Array#to_h from pairs and sort! with a comparator block

Two remaining Array method gaps:

  • to_h on an array of [key, value] pairs was unresolved. Build a poly_poly_hash by extracting [0]/[1] from each poly-boxed inner pair; analyze types the result poly_poly_hash. Keys/values keep their boxed types, so h[:a] / h["x"] / h[1] all look up.
  • sort! { |a, b| ... } silently ignored the block and did a default ascending sort. Honour the comparator with an in-place bubble sort (via sp_Array_get/set so the array offset is respected) for int / str / float arrays.

[[:a, 1], [:b, 2]].to_h[:a] # => 1 (was: unresolved) a = [3,1,4]; a.sort! { |x,y| y<=>x }; a # => [4,3,1] (block was ignored)

With Array#fill(value, range) (the range-args cluster), this closes the remaining sub-parts of #1224.

Fixes #1224

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
f1b5229f4adf
Parent
1e6cd661640f

spinel_analyze.rbmodifiedView file

@@ -5540,6 +5540,12 @@
55405540 if is_hash_type(rt) == 1
55415541 return rt
55425542 end
5543+ # `[[k,v], ...].to_h` on an array of pairs builds a hash; keys and
5544+ # values keep their boxed types, so the result is a poly_poly_hash.
5545+ if rt == "poly_array"
5546+ @needs_poly_poly_hash = 1
5547+ return "poly_poly_hash"
5548+ end
55435549 end
55445550 end
55455551 if mname == "fdiv"