@blazetrails/ruby-compat 0.0.0-stage → 0.1.0-alpha0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (622) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +6 -0
  3. package/README.md +440 -2
  4. package/dist/argument-error.d.ts +15 -0
  5. package/dist/argument-error.js +15 -0
  6. package/dist/argument-error.js.map +1 -0
  7. package/dist/array.d.ts +415 -0
  8. package/dist/array.js +1330 -0
  9. package/dist/array.js.map +1 -0
  10. package/dist/async-context-adapter.d.ts +19 -0
  11. package/dist/async-context-adapter.js +139 -0
  12. package/dist/async-context-adapter.js.map +1 -0
  13. package/dist/backtrace-location.d.ts +77 -0
  14. package/dist/backtrace-location.js +155 -0
  15. package/dist/backtrace-location.js.map +1 -0
  16. package/dist/base64.d.ts +73 -0
  17. package/dist/base64.js +164 -0
  18. package/dist/base64.js.map +1 -0
  19. package/dist/benchmark.d.ts +19 -0
  20. package/dist/benchmark.js +16 -0
  21. package/dist/benchmark.js.map +1 -0
  22. package/dist/big-decimal.d.ts +110 -0
  23. package/dist/big-decimal.js +582 -0
  24. package/dist/big-decimal.js.map +1 -0
  25. package/dist/bundler.d.ts +44 -0
  26. package/dist/bundler.js +101 -0
  27. package/dist/bundler.js.map +1 -0
  28. package/dist/cgi.d.ts +89 -0
  29. package/dist/cgi.js +168 -0
  30. package/dist/cgi.js.map +1 -0
  31. package/dist/child-process-adapter.d.ts +110 -0
  32. package/dist/child-process-adapter.js +272 -0
  33. package/dist/child-process-adapter.js.map +1 -0
  34. package/dist/class-module.d.ts +10 -0
  35. package/dist/class-module.js +10 -0
  36. package/dist/class-module.js.map +1 -0
  37. package/dist/classpath.d.ts +90 -0
  38. package/dist/classpath.js +207 -0
  39. package/dist/classpath.js.map +1 -0
  40. package/dist/closed-queue-error.d.ts +10 -0
  41. package/dist/closed-queue-error.js +10 -0
  42. package/dist/closed-queue-error.js.map +1 -0
  43. package/dist/comparable.d.ts +127 -0
  44. package/dist/comparable.js +376 -0
  45. package/dist/comparable.js.map +1 -0
  46. package/dist/complex.d.ts +48 -0
  47. package/dist/complex.js +162 -0
  48. package/dist/complex.js.map +1 -0
  49. package/dist/concurrent/atomic-boolean.d.ts +24 -0
  50. package/dist/concurrent/atomic-boolean.js +43 -0
  51. package/dist/concurrent/atomic-boolean.js.map +1 -0
  52. package/dist/concurrent/atomic-fixnum.d.ts +21 -0
  53. package/dist/concurrent/atomic-fixnum.js +35 -0
  54. package/dist/concurrent/atomic-fixnum.js.map +1 -0
  55. package/dist/concurrent/count-down-latch.d.ts +20 -0
  56. package/dist/concurrent/count-down-latch.js +50 -0
  57. package/dist/concurrent/count-down-latch.js.map +1 -0
  58. package/dist/concurrent/cyclic-barrier.d.ts +18 -0
  59. package/dist/concurrent/cyclic-barrier.js +50 -0
  60. package/dist/concurrent/cyclic-barrier.js.map +1 -0
  61. package/dist/concurrent/event.d.ts +19 -0
  62. package/dist/concurrent/event.js +31 -0
  63. package/dist/concurrent/event.js.map +1 -0
  64. package/dist/concurrent/map.d.ts +149 -0
  65. package/dist/concurrent/map.js +202 -0
  66. package/dist/concurrent/map.js.map +1 -0
  67. package/dist/concurrent/read-write-lock.d.ts +25 -0
  68. package/dist/concurrent/read-write-lock.js +70 -0
  69. package/dist/concurrent/read-write-lock.js.map +1 -0
  70. package/dist/concurrent/semaphore.d.ts +24 -0
  71. package/dist/concurrent/semaphore.js +74 -0
  72. package/dist/concurrent/semaphore.js.map +1 -0
  73. package/dist/concurrent/timer-task.d.ts +52 -0
  74. package/dist/concurrent/timer-task.js +112 -0
  75. package/dist/concurrent/timer-task.js.map +1 -0
  76. package/dist/constants.generated.d.ts +2 -0
  77. package/dist/constants.generated.js +64 -0
  78. package/dist/constants.generated.js.map +1 -0
  79. package/dist/converter-not-found-error.d.ts +14 -0
  80. package/dist/converter-not-found-error.js +14 -0
  81. package/dist/converter-not-found-error.js.map +1 -0
  82. package/dist/crypto-adapter.d.ts +64 -0
  83. package/dist/crypto-adapter.js +365 -0
  84. package/dist/crypto-adapter.js.map +1 -0
  85. package/dist/delegate.d.ts +156 -0
  86. package/dist/delegate.js +306 -0
  87. package/dist/delegate.js.map +1 -0
  88. package/dist/digest.d.ts +99 -0
  89. package/dist/digest.js +131 -0
  90. package/dist/digest.js.map +1 -0
  91. package/dist/dir.d.ts +218 -0
  92. package/dist/dir.js +599 -0
  93. package/dist/dir.js.map +1 -0
  94. package/dist/encoding-error.d.ts +14 -0
  95. package/dist/encoding-error.js +17 -0
  96. package/dist/encoding-error.js.map +1 -0
  97. package/dist/encoding.d.ts +121 -0
  98. package/dist/encoding.js +306 -0
  99. package/dist/encoding.js.map +1 -0
  100. package/dist/ensure.d.ts +15 -0
  101. package/dist/ensure.js +35 -0
  102. package/dist/ensure.js.map +1 -0
  103. package/dist/enumerable.d.ts +375 -0
  104. package/dist/enumerable.js +1100 -0
  105. package/dist/enumerable.js.map +1 -0
  106. package/dist/enumerator.d.ts +321 -0
  107. package/dist/enumerator.js +642 -0
  108. package/dist/enumerator.js.map +1 -0
  109. package/dist/eof-error.d.ts +14 -0
  110. package/dist/eof-error.js +14 -0
  111. package/dist/eof-error.js.map +1 -0
  112. package/dist/errno.d.ts +327 -0
  113. package/dist/errno.js +452 -0
  114. package/dist/errno.js.map +1 -0
  115. package/dist/exc-detailed-message.d.ts +15 -0
  116. package/dist/exc-detailed-message.js +106 -0
  117. package/dist/exc-detailed-message.js.map +1 -0
  118. package/dist/exc-to-s.d.ts +10 -0
  119. package/dist/exc-to-s.js +21 -0
  120. package/dist/exc-to-s.js.map +1 -0
  121. package/dist/exception.d.ts +34 -0
  122. package/dist/exception.js +99 -0
  123. package/dist/exception.js.map +1 -0
  124. package/dist/fiber-error.d.ts +12 -0
  125. package/dist/fiber-error.js +12 -0
  126. package/dist/fiber-error.js.map +1 -0
  127. package/dist/fiber.d.ts +51 -0
  128. package/dist/fiber.js +178 -0
  129. package/dist/fiber.js.map +1 -0
  130. package/dist/file-utils.d.ts +480 -0
  131. package/dist/file-utils.js +1823 -0
  132. package/dist/file-utils.js.map +1 -0
  133. package/dist/file.d.ts +635 -0
  134. package/dist/file.js +1312 -0
  135. package/dist/file.js.map +1 -0
  136. package/dist/float-domain-error.d.ts +17 -0
  137. package/dist/float-domain-error.js +17 -0
  138. package/dist/float-domain-error.js.map +1 -0
  139. package/dist/fork-children.d.ts +23 -0
  140. package/dist/fork-children.js +32 -0
  141. package/dist/fork-children.js.map +1 -0
  142. package/dist/frozen-error.d.ts +33 -0
  143. package/dist/frozen-error.js +42 -0
  144. package/dist/frozen-error.js.map +1 -0
  145. package/dist/fs-adapter.d.ts +158 -0
  146. package/dist/fs-adapter.js +253 -0
  147. package/dist/fs-adapter.js.map +1 -0
  148. package/dist/gem/deprecate.d.ts +10 -0
  149. package/dist/gem/deprecate.js +8 -0
  150. package/dist/gem/deprecate.js.map +1 -0
  151. package/dist/gem/requirement.d.ts +64 -0
  152. package/dist/gem/requirement.js +91 -0
  153. package/dist/gem/requirement.js.map +1 -0
  154. package/dist/gem/version.d.ts +50 -0
  155. package/dist/gem/version.js +148 -0
  156. package/dist/gem/version.js.map +1 -0
  157. package/dist/gem.d.ts +59 -0
  158. package/dist/gem.js +82 -0
  159. package/dist/gem.js.map +1 -0
  160. package/dist/hash.d.ts +967 -0
  161. package/dist/hash.js +1572 -0
  162. package/dist/hash.js.map +1 -0
  163. package/dist/http-adapter.d.ts +123 -0
  164. package/dist/http-adapter.js +220 -0
  165. package/dist/http-adapter.js.map +1 -0
  166. package/dist/immediate-executor.d.ts +20 -0
  167. package/dist/immediate-executor.js +39 -0
  168. package/dist/immediate-executor.js.map +1 -0
  169. package/dist/include.d.ts +778 -0
  170. package/dist/include.js +2195 -0
  171. package/dist/include.js.map +1 -0
  172. package/dist/index-error.d.ts +13 -0
  173. package/dist/index-error.js +13 -0
  174. package/dist/index-error.js.map +1 -0
  175. package/dist/index.d.ts +174 -0
  176. package/dist/index.js +166 -0
  177. package/dist/index.js.map +1 -0
  178. package/dist/invalid-byte-sequence-error.d.ts +62 -0
  179. package/dist/invalid-byte-sequence-error.js +75 -0
  180. package/dist/invalid-byte-sequence-error.js.map +1 -0
  181. package/dist/io-error.d.ts +14 -0
  182. package/dist/io-error.js +17 -0
  183. package/dist/io-error.js.map +1 -0
  184. package/dist/io.d.ts +867 -0
  185. package/dist/io.js +1960 -0
  186. package/dist/io.js.map +1 -0
  187. package/dist/ipaddr.d.ts +79 -0
  188. package/dist/ipaddr.js +405 -0
  189. package/dist/ipaddr.js.map +1 -0
  190. package/dist/json.d.ts +67 -0
  191. package/dist/json.js +185 -0
  192. package/dist/json.js.map +1 -0
  193. package/dist/kernel-catch.d.ts +59 -0
  194. package/dist/kernel-catch.js +184 -0
  195. package/dist/kernel-catch.js.map +1 -0
  196. package/dist/kernel-float.d.ts +19 -0
  197. package/dist/kernel-float.js +54 -0
  198. package/dist/kernel-float.js.map +1 -0
  199. package/dist/kernel-fork.d.ts +30 -0
  200. package/dist/kernel-fork.js +72 -0
  201. package/dist/kernel-fork.js.map +1 -0
  202. package/dist/kernel-format.d.ts +27 -0
  203. package/dist/kernel-format.js +901 -0
  204. package/dist/kernel-format.js.map +1 -0
  205. package/dist/kernel-hash.d.ts +7 -0
  206. package/dist/kernel-hash.js +33 -0
  207. package/dist/kernel-hash.js.map +1 -0
  208. package/dist/kernel-integer.d.ts +49 -0
  209. package/dist/kernel-integer.js +170 -0
  210. package/dist/kernel-integer.js.map +1 -0
  211. package/dist/kernel-rand.d.ts +16 -0
  212. package/dist/kernel-rand.js +237 -0
  213. package/dist/kernel-rand.js.map +1 -0
  214. package/dist/kernel-system.d.ts +40 -0
  215. package/dist/kernel-system.js +97 -0
  216. package/dist/kernel-system.js.map +1 -0
  217. package/dist/kernel-warn.d.ts +35 -0
  218. package/dist/kernel-warn.js +73 -0
  219. package/dist/kernel-warn.js.map +1 -0
  220. package/dist/key-error.d.ts +44 -0
  221. package/dist/key-error.js +59 -0
  222. package/dist/key-error.js.map +1 -0
  223. package/dist/keyword-splat.d.ts +41 -0
  224. package/dist/keyword-splat.js +65 -0
  225. package/dist/keyword-splat.js.map +1 -0
  226. package/dist/load-error.d.ts +19 -0
  227. package/dist/load-error.js +19 -0
  228. package/dist/load-error.js.map +1 -0
  229. package/dist/load.d.ts +121 -0
  230. package/dist/load.js +263 -0
  231. package/dist/load.js.map +1 -0
  232. package/dist/loaded-features.d.ts +13 -0
  233. package/dist/loaded-features.js +15 -0
  234. package/dist/loaded-features.js.map +1 -0
  235. package/dist/local-jump-error.d.ts +12 -0
  236. package/dist/local-jump-error.js +12 -0
  237. package/dist/local-jump-error.js.map +1 -0
  238. package/dist/logger/formatter.d.ts +21 -0
  239. package/dist/logger/formatter.js +43 -0
  240. package/dist/logger/formatter.js.map +1 -0
  241. package/dist/logger/log-device.d.ts +52 -0
  242. package/dist/logger/log-device.js +104 -0
  243. package/dist/logger/log-device.js.map +1 -0
  244. package/dist/logger/severity.d.ts +23 -0
  245. package/dist/logger/severity.js +42 -0
  246. package/dist/logger/severity.js.map +1 -0
  247. package/dist/logger.d.ts +127 -0
  248. package/dist/logger.js +215 -0
  249. package/dist/logger.js.map +1 -0
  250. package/dist/marshal.d.ts +83 -0
  251. package/dist/marshal.js +1487 -0
  252. package/dist/marshal.js.map +1 -0
  253. package/dist/match-data.d.ts +161 -0
  254. package/dist/match-data.js +284 -0
  255. package/dist/match-data.js.map +1 -0
  256. package/dist/method-cache.d.ts +17 -0
  257. package/dist/method-cache.js +19 -0
  258. package/dist/method-cache.js.map +1 -0
  259. package/dist/method-missing-proxy.d.ts +53 -0
  260. package/dist/method-missing-proxy.js +154 -0
  261. package/dist/method-missing-proxy.js.map +1 -0
  262. package/dist/method.d.ts +132 -0
  263. package/dist/method.js +320 -0
  264. package/dist/method.js.map +1 -0
  265. package/dist/monitor.d.ts +114 -0
  266. package/dist/monitor.js +270 -0
  267. package/dist/monitor.js.map +1 -0
  268. package/dist/mutex.d.ts +51 -0
  269. package/dist/mutex.js +150 -0
  270. package/dist/mutex.js.map +1 -0
  271. package/dist/name-error.d.ts +45 -0
  272. package/dist/name-error.js +54 -0
  273. package/dist/name-error.js.map +1 -0
  274. package/dist/net/http/exceptions.d.ts +31 -0
  275. package/dist/net/http/exceptions.js +46 -0
  276. package/dist/net/http/exceptions.js.map +1 -0
  277. package/dist/net/http/request.d.ts +137 -0
  278. package/dist/net/http/request.js +559 -0
  279. package/dist/net/http/request.js.map +1 -0
  280. package/dist/net/http/requests.d.ts +197 -0
  281. package/dist/net/http/requests.js +197 -0
  282. package/dist/net/http/requests.js.map +1 -0
  283. package/dist/net/http/response.d.ts +141 -0
  284. package/dist/net/http/response.js +416 -0
  285. package/dist/net/http/response.js.map +1 -0
  286. package/dist/net/http/responses.d.ts +345 -0
  287. package/dist/net/http/responses.js +486 -0
  288. package/dist/net/http/responses.js.map +1 -0
  289. package/dist/net/http.d.ts +278 -0
  290. package/dist/net/http.js +760 -0
  291. package/dist/net/http.js.map +1 -0
  292. package/dist/net/protocol.d.ts +227 -0
  293. package/dist/net/protocol.js +392 -0
  294. package/dist/net/protocol.js.map +1 -0
  295. package/dist/nil-class.d.ts +10 -0
  296. package/dist/nil-class.js +27 -0
  297. package/dist/nil-class.js.map +1 -0
  298. package/dist/no-method-error.d.ts +38 -0
  299. package/dist/no-method-error.js +45 -0
  300. package/dist/no-method-error.js.map +1 -0
  301. package/dist/not-implemented-error.d.ts +13 -0
  302. package/dist/not-implemented-error.js +14 -0
  303. package/dist/not-implemented-error.js.map +1 -0
  304. package/dist/numeric.d.ts +211 -0
  305. package/dist/numeric.js +802 -0
  306. package/dist/numeric.js.map +1 -0
  307. package/dist/object-space.d.ts +34 -0
  308. package/dist/object-space.js +152 -0
  309. package/dist/object-space.js.map +1 -0
  310. package/dist/object.d.ts +908 -0
  311. package/dist/object.js +2238 -0
  312. package/dist/object.js.map +1 -0
  313. package/dist/open-uri.d.ts +180 -0
  314. package/dist/open-uri.js +402 -0
  315. package/dist/open-uri.js.map +1 -0
  316. package/dist/open3.d.ts +69 -0
  317. package/dist/open3.js +134 -0
  318. package/dist/open3.js.map +1 -0
  319. package/dist/openssl.d.ts +479 -0
  320. package/dist/openssl.js +1052 -0
  321. package/dist/openssl.js.map +1 -0
  322. package/dist/optparse.d.ts +130 -0
  323. package/dist/optparse.js +457 -0
  324. package/dist/optparse.js.map +1 -0
  325. package/dist/os-adapter.d.ts +20 -0
  326. package/dist/os-adapter.js +95 -0
  327. package/dist/os-adapter.js.map +1 -0
  328. package/dist/pathname.d.ts +71 -0
  329. package/dist/pathname.js +394 -0
  330. package/dist/pathname.js.map +1 -0
  331. package/dist/pp.d.ts +60 -0
  332. package/dist/pp.js +195 -0
  333. package/dist/pp.js.map +1 -0
  334. package/dist/pretty-print.d.ts +89 -0
  335. package/dist/pretty-print.js +232 -0
  336. package/dist/pretty-print.js.map +1 -0
  337. package/dist/process-adapter.d.ts +224 -0
  338. package/dist/process-adapter.js +878 -0
  339. package/dist/process-adapter.js.map +1 -0
  340. package/dist/process.d.ts +192 -0
  341. package/dist/process.js +403 -0
  342. package/dist/process.js.map +1 -0
  343. package/dist/psych/class-loader.d.ts +92 -0
  344. package/dist/psych/class-loader.js +139 -0
  345. package/dist/psych/class-loader.js.map +1 -0
  346. package/dist/psych/coder.d.ts +144 -0
  347. package/dist/psych/coder.js +176 -0
  348. package/dist/psych/coder.js.map +1 -0
  349. package/dist/psych/core-ext.d.ts +8 -0
  350. package/dist/psych/core-ext.js +10 -0
  351. package/dist/psych/core-ext.js.map +1 -0
  352. package/dist/psych/emitter.d.ts +116 -0
  353. package/dist/psych/emitter.js +1130 -0
  354. package/dist/psych/emitter.js.map +1 -0
  355. package/dist/psych/exception.d.ts +43 -0
  356. package/dist/psych/exception.js +54 -0
  357. package/dist/psych/exception.js.map +1 -0
  358. package/dist/psych/handler.d.ts +59 -0
  359. package/dist/psych/handler.js +95 -0
  360. package/dist/psych/handler.js.map +1 -0
  361. package/dist/psych/handlers/document-stream.d.ts +17 -0
  362. package/dist/psych/handlers/document-stream.js +26 -0
  363. package/dist/psych/handlers/document-stream.js.map +1 -0
  364. package/dist/psych/nodes/alias.d.ts +15 -0
  365. package/dist/psych/nodes/alias.js +22 -0
  366. package/dist/psych/nodes/alias.js.map +1 -0
  367. package/dist/psych/nodes/document.d.ts +23 -0
  368. package/dist/psych/nodes/document.js +35 -0
  369. package/dist/psych/nodes/document.js.map +1 -0
  370. package/dist/psych/nodes/mapping.d.ts +25 -0
  371. package/dist/psych/nodes/mapping.js +35 -0
  372. package/dist/psych/nodes/mapping.js.map +1 -0
  373. package/dist/psych/nodes/node.d.ts +59 -0
  374. package/dist/psych/nodes/node.js +79 -0
  375. package/dist/psych/nodes/node.js.map +1 -0
  376. package/dist/psych/nodes/scalar.d.ts +35 -0
  377. package/dist/psych/nodes/scalar.js +47 -0
  378. package/dist/psych/nodes/scalar.js.map +1 -0
  379. package/dist/psych/nodes/sequence.d.ts +25 -0
  380. package/dist/psych/nodes/sequence.js +35 -0
  381. package/dist/psych/nodes/sequence.js.map +1 -0
  382. package/dist/psych/nodes/stream.d.ts +23 -0
  383. package/dist/psych/nodes/stream.js +31 -0
  384. package/dist/psych/nodes/stream.js.map +1 -0
  385. package/dist/psych/omap.d.ts +9 -0
  386. package/dist/psych/omap.js +9 -0
  387. package/dist/psych/omap.js.map +1 -0
  388. package/dist/psych/parser.d.ts +41 -0
  389. package/dist/psych/parser.js +139 -0
  390. package/dist/psych/parser.js.map +1 -0
  391. package/dist/psych/scalar-scanner.d.ts +35 -0
  392. package/dist/psych/scalar-scanner.js +173 -0
  393. package/dist/psych/scalar-scanner.js.map +1 -0
  394. package/dist/psych/syntax-error.d.ts +23 -0
  395. package/dist/psych/syntax-error.js +35 -0
  396. package/dist/psych/syntax-error.js.map +1 -0
  397. package/dist/psych/tree-builder.d.ts +51 -0
  398. package/dist/psych/tree-builder.js +118 -0
  399. package/dist/psych/tree-builder.js.map +1 -0
  400. package/dist/psych/visitors/depth-first.d.ts +27 -0
  401. package/dist/psych/visitors/depth-first.js +37 -0
  402. package/dist/psych/visitors/depth-first.js.map +1 -0
  403. package/dist/psych/visitors/emitter.d.ts +32 -0
  404. package/dist/psych/visitors/emitter.js +63 -0
  405. package/dist/psych/visitors/emitter.js.map +1 -0
  406. package/dist/psych/visitors/to-ruby.d.ts +110 -0
  407. package/dist/psych/visitors/to-ruby.js +396 -0
  408. package/dist/psych/visitors/to-ruby.js.map +1 -0
  409. package/dist/psych/visitors/visitor.d.ts +11 -0
  410. package/dist/psych/visitors/visitor.js +17 -0
  411. package/dist/psych/visitors/visitor.js.map +1 -0
  412. package/dist/psych/visitors/yaml-tree.d.ts +182 -0
  413. package/dist/psych/visitors/yaml-tree.js +593 -0
  414. package/dist/psych/visitors/yaml-tree.js.map +1 -0
  415. package/dist/psych-adapter.d.ts +65 -0
  416. package/dist/psych-adapter.js +121 -0
  417. package/dist/psych-adapter.js.map +1 -0
  418. package/dist/psych-yaml.d.ts +2 -0
  419. package/dist/psych-yaml.js +5 -0
  420. package/dist/psych-yaml.js.map +1 -0
  421. package/dist/psych.d.ts +257 -0
  422. package/dist/psych.js +332 -0
  423. package/dist/psych.js.map +1 -0
  424. package/dist/queue.d.ts +129 -0
  425. package/dist/queue.js +215 -0
  426. package/dist/queue.js.map +1 -0
  427. package/dist/racc/parser.d.ts +70 -0
  428. package/dist/racc/parser.js +206 -0
  429. package/dist/racc/parser.js.map +1 -0
  430. package/dist/range-error.d.ts +15 -0
  431. package/dist/range-error.js +15 -0
  432. package/dist/range-error.js.map +1 -0
  433. package/dist/range.d.ts +166 -0
  434. package/dist/range.js +421 -0
  435. package/dist/range.js.map +1 -0
  436. package/dist/rational.d.ts +167 -0
  437. package/dist/rational.js +379 -0
  438. package/dist/rational.js.map +1 -0
  439. package/dist/rb-config.d.ts +33 -0
  440. package/dist/rb-config.js +53 -0
  441. package/dist/rb-config.js.map +1 -0
  442. package/dist/rb-equal.d.ts +66 -0
  443. package/dist/rb-equal.js +261 -0
  444. package/dist/rb-equal.js.map +1 -0
  445. package/dist/rb-hash.d.ts +26 -0
  446. package/dist/rb-hash.js +108 -0
  447. package/dist/rb-hash.js.map +1 -0
  448. package/dist/regexp.d.ts +82 -0
  449. package/dist/regexp.js +191 -0
  450. package/dist/regexp.js.map +1 -0
  451. package/dist/repl-adapter.d.ts +188 -0
  452. package/dist/repl-adapter.js +388 -0
  453. package/dist/repl-adapter.js.map +1 -0
  454. package/dist/resolv.d.ts +30 -0
  455. package/dist/resolv.js +48 -0
  456. package/dist/resolv.js.map +1 -0
  457. package/dist/ruby-empty.d.ts +28 -0
  458. package/dist/ruby-empty.js +40 -0
  459. package/dist/ruby-empty.js.map +1 -0
  460. package/dist/ruby-platform.d.ts +39 -0
  461. package/dist/ruby-platform.js +49 -0
  462. package/dist/ruby-platform.js.map +1 -0
  463. package/dist/runtime-error.d.ts +15 -0
  464. package/dist/runtime-error.js +16 -0
  465. package/dist/runtime-error.js.map +1 -0
  466. package/dist/scheduled-task.d.ts +73 -0
  467. package/dist/scheduled-task.js +150 -0
  468. package/dist/scheduled-task.js.map +1 -0
  469. package/dist/secure-random.d.ts +33 -0
  470. package/dist/secure-random.js +78 -0
  471. package/dist/secure-random.js.map +1 -0
  472. package/dist/set.d.ts +158 -0
  473. package/dist/set.js +352 -0
  474. package/dist/set.js.map +1 -0
  475. package/dist/shellwords.d.ts +27 -0
  476. package/dist/shellwords.js +53 -0
  477. package/dist/shellwords.js.map +1 -0
  478. package/dist/signal-exception.d.ts +21 -0
  479. package/dist/signal-exception.js +21 -0
  480. package/dist/signal-exception.js.map +1 -0
  481. package/dist/socket.d.ts +230 -0
  482. package/dist/socket.js +484 -0
  483. package/dist/socket.js.map +1 -0
  484. package/dist/standard-error.d.ts +18 -0
  485. package/dist/standard-error.js +23 -0
  486. package/dist/standard-error.js.map +1 -0
  487. package/dist/stop-iteration.d.ts +10 -0
  488. package/dist/stop-iteration.js +10 -0
  489. package/dist/stop-iteration.js.map +1 -0
  490. package/dist/string/b.d.ts +19 -0
  491. package/dist/string/b.js +28 -0
  492. package/dist/string/b.js.map +1 -0
  493. package/dist/string/byte-methods.d.ts +57 -0
  494. package/dist/string/byte-methods.js +266 -0
  495. package/dist/string/byte-methods.js.map +1 -0
  496. package/dist/string/bytes.d.ts +35 -0
  497. package/dist/string/bytes.js +123 -0
  498. package/dist/string/bytes.js.map +1 -0
  499. package/dist/string/case-mapping.d.ts +57 -0
  500. package/dist/string/case-mapping.js +192 -0
  501. package/dist/string/case-mapping.js.map +1 -0
  502. package/dist/string/chomp.d.ts +15 -0
  503. package/dist/string/chomp.js +32 -0
  504. package/dist/string/chomp.js.map +1 -0
  505. package/dist/string/convert.d.ts +55 -0
  506. package/dist/string/convert.js +316 -0
  507. package/dist/string/convert.js.map +1 -0
  508. package/dist/string/delete.d.ts +14 -0
  509. package/dist/string/delete.js +17 -0
  510. package/dist/string/delete.js.map +1 -0
  511. package/dist/string/each.d.ts +108 -0
  512. package/dist/string/each.js +305 -0
  513. package/dist/string/each.js.map +1 -0
  514. package/dist/string/encode.d.ts +37 -0
  515. package/dist/string/encode.js +268 -0
  516. package/dist/string/encode.js.map +1 -0
  517. package/dist/string/force-encoding.d.ts +72 -0
  518. package/dist/string/force-encoding.js +147 -0
  519. package/dist/string/force-encoding.js.map +1 -0
  520. package/dist/string/inspect.d.ts +17 -0
  521. package/dist/string/inspect.js +81 -0
  522. package/dist/string/inspect.js.map +1 -0
  523. package/dist/string/method-table.d.ts +174 -0
  524. package/dist/string/method-table.js +805 -0
  525. package/dist/string/method-table.js.map +1 -0
  526. package/dist/string/scrub.d.ts +12 -0
  527. package/dist/string/scrub.js +33 -0
  528. package/dist/string/scrub.js.map +1 -0
  529. package/dist/string/slice.d.ts +26 -0
  530. package/dist/string/slice.js +73 -0
  531. package/dist/string/slice.js.map +1 -0
  532. package/dist/string/split.d.ts +11 -0
  533. package/dist/string/split.js +44 -0
  534. package/dist/string/split.js.map +1 -0
  535. package/dist/string/sub.d.ts +114 -0
  536. package/dist/string/sub.js +371 -0
  537. package/dist/string/sub.js.map +1 -0
  538. package/dist/string/succ.d.ts +14 -0
  539. package/dist/string/succ.js +118 -0
  540. package/dist/string/succ.js.map +1 -0
  541. package/dist/string/support.d.ts +135 -0
  542. package/dist/string/support.js +283 -0
  543. package/dist/string/support.js.map +1 -0
  544. package/dist/string/tr.d.ts +46 -0
  545. package/dist/string/tr.js +156 -0
  546. package/dist/string/tr.js.map +1 -0
  547. package/dist/string-io.d.ts +166 -0
  548. package/dist/string-io.js +248 -0
  549. package/dist/string-io.js.map +1 -0
  550. package/dist/string-scanner.d.ts +133 -0
  551. package/dist/string-scanner.js +248 -0
  552. package/dist/string-scanner.js.map +1 -0
  553. package/dist/struct.d.ts +54 -0
  554. package/dist/struct.js +222 -0
  555. package/dist/struct.js.map +1 -0
  556. package/dist/symbol.d.ts +48 -0
  557. package/dist/symbol.js +107 -0
  558. package/dist/symbol.js.map +1 -0
  559. package/dist/tempfile.d.ts +173 -0
  560. package/dist/tempfile.js +290 -0
  561. package/dist/tempfile.js.map +1 -0
  562. package/dist/temporal-tag.d.ts +23 -0
  563. package/dist/temporal-tag.js +29 -0
  564. package/dist/temporal-tag.js.map +1 -0
  565. package/dist/thread-error.d.ts +13 -0
  566. package/dist/thread-error.js +13 -0
  567. package/dist/thread-error.js.map +1 -0
  568. package/dist/thread-pool-executor.d.ts +119 -0
  569. package/dist/thread-pool-executor.js +250 -0
  570. package/dist/thread-pool-executor.js.map +1 -0
  571. package/dist/thread.d.ts +211 -0
  572. package/dist/thread.js +495 -0
  573. package/dist/thread.js.map +1 -0
  574. package/dist/timeout.d.ts +29 -0
  575. package/dist/timeout.js +41 -0
  576. package/dist/timeout.js.map +1 -0
  577. package/dist/tse.d.ts +40 -0
  578. package/dist/tse.js +62 -0
  579. package/dist/tse.js.map +1 -0
  580. package/dist/type-error.d.ts +14 -0
  581. package/dist/type-error.js +15 -0
  582. package/dist/type-error.js.map +1 -0
  583. package/dist/undefined-conversion-error.d.ts +10 -0
  584. package/dist/undefined-conversion-error.js +10 -0
  585. package/dist/undefined-conversion-error.js.map +1 -0
  586. package/dist/uri/common.d.ts +209 -0
  587. package/dist/uri/common.js +369 -0
  588. package/dist/uri/common.js.map +1 -0
  589. package/dist/uri/generic.d.ts +283 -0
  590. package/dist/uri/generic.js +810 -0
  591. package/dist/uri/generic.js.map +1 -0
  592. package/dist/uri/http.d.ts +23 -0
  593. package/dist/uri/http.js +30 -0
  594. package/dist/uri/http.js.map +1 -0
  595. package/dist/uri/https.d.ts +13 -0
  596. package/dist/uri/https.js +15 -0
  597. package/dist/uri/https.js.map +1 -0
  598. package/dist/uri/rfc2396-parser.d.ts +70 -0
  599. package/dist/uri/rfc2396-parser.js +264 -0
  600. package/dist/uri/rfc2396-parser.js.map +1 -0
  601. package/dist/uri/rfc3986-parser.d.ts +46 -0
  602. package/dist/uri/rfc3986-parser.js +171 -0
  603. package/dist/uri/rfc3986-parser.js.map +1 -0
  604. package/dist/uri.d.ts +13 -0
  605. package/dist/uri.js +13 -0
  606. package/dist/uri.js.map +1 -0
  607. package/dist/variable.d.ts +183 -0
  608. package/dist/variable.js +463 -0
  609. package/dist/variable.js.map +1 -0
  610. package/dist/verbose.d.ts +21 -0
  611. package/dist/verbose.js +26 -0
  612. package/dist/verbose.js.map +1 -0
  613. package/dist/yaml.d.ts +9 -0
  614. package/dist/yaml.js +9 -0
  615. package/dist/yaml.js.map +1 -0
  616. package/dist/zlib-adapter.d.ts +117 -0
  617. package/dist/zlib-adapter.js +250 -0
  618. package/dist/zlib-adapter.js.map +1 -0
  619. package/dist/zlib.d.ts +248 -0
  620. package/dist/zlib.js +362 -0
  621. package/dist/zlib.js.map +1 -0
  622. package/package.json +82 -3
package/dist/hash.js ADDED
@@ -0,0 +1,1572 @@
1
+ import { ArgumentError } from "./argument-error.js";
2
+ import { aryDelete } from "./array.js";
3
+ import { Enumerator } from "./enumerator.js";
4
+ import { FrozenError } from "./frozen-error.js";
5
+ import { KeyError } from "./key-error.js";
6
+ import { isPlainHash, rbBuiltinClassName, rbInspect, rbObjClass } from "./object.js";
7
+ import { rbEql, rbEqual } from "./rb-equal.js";
8
+ import { rbHash } from "./rb-hash.js";
9
+ import { RuntimeError } from "./runtime-error.js";
10
+ import { isSymbol, symbolToS } from "./symbol.js";
11
+ import { TypeError } from "./type-error.js";
12
+ const BLOCK = Symbol.for("@blazetrails/ruby-compat:block");
13
+ const UNDEF = Symbol("Qundef");
14
+ /** @noRailsEquivalent PERMANENT — Ruby's `&` block-pass, whose `rb_block_given_p` (`vendor/ruby/v3.3.11/eval.c:866`) TypeScript has no equivalent of; one mark serves every yield signature. */
15
+ export function block(fn) {
16
+ let blk;
17
+ switch (fn.length) {
18
+ case 0:
19
+ blk = function (...args) {
20
+ return fn.apply(this, args);
21
+ };
22
+ break;
23
+ case 1:
24
+ blk = function (_a) {
25
+ // eslint-disable-next-line prefer-rest-params
26
+ return fn.apply(this, arguments);
27
+ };
28
+ break;
29
+ case 2:
30
+ blk = function (_a, _b) {
31
+ // eslint-disable-next-line prefer-rest-params
32
+ return fn.apply(this, arguments);
33
+ };
34
+ break;
35
+ default:
36
+ blk = function (...args) {
37
+ return fn.apply(this, args);
38
+ };
39
+ Object.defineProperty(blk, "length", { value: fn.length });
40
+ }
41
+ blk[BLOCK] = true;
42
+ return blk;
43
+ }
44
+ /**
45
+ * `rb_block_given_p` (`vendor/ruby/v3.3.11/eval.c:866`): whether a trailing
46
+ * argument is a {@link block}-marked `&block` rather than a positional callable.
47
+ *
48
+ * @noRailsEquivalent PERMANENT
49
+ */
50
+ export function rbBlockGivenP(value) {
51
+ return typeof value === "function" && value[BLOCK] === true;
52
+ }
53
+ function ownMethod(hash, mid) {
54
+ const proto = Object.getPrototypeOf(hash);
55
+ if (proto === Object.prototype || proto === null)
56
+ return undefined;
57
+ if (hash instanceof Map)
58
+ return undefined;
59
+ const own = hash[mid];
60
+ return typeof own === "function" ? own : undefined;
61
+ }
62
+ /**
63
+ * `rb_hash_fetch_m` dispatches on `argc` and `rb_block_given_p`, so the arms
64
+ * share one body over a rest parameter: an absent second argument is the
65
+ * raising arm, and an explicitly-passed `undefined` is a default, exactly as
66
+ * Ruby's `nil` is.
67
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#fetch` (`vendor/ruby/v3.3.11/hash.c:2176`).
68
+ * @perf 2x — PERMANENT
69
+ */
70
+ export function fetch(receiver, key, arg, ...more) {
71
+ const given = arguments.length;
72
+ const plain = Object.getPrototypeOf(receiver) === Object.prototype;
73
+ if (plain && more.length === 0) {
74
+ const value = receiver[key];
75
+ if (value !== undefined && Object.hasOwn(receiver, key))
76
+ return value;
77
+ }
78
+ if (!plain) {
79
+ const own = ownMethod(receiver, "fetch");
80
+ if (own) {
81
+ if (given === 2)
82
+ return own.call(receiver, key);
83
+ if (more.length === 0)
84
+ return own.call(receiver, key, arg);
85
+ return own.call(receiver, key, arg, ...more);
86
+ }
87
+ }
88
+ const rest = given === 2 ? [] : [arg, ...more];
89
+ const blockGiven = rbBlockGivenP(rest[rest.length - 1]);
90
+ const argc = 1 + rest.length - (blockGiven ? 1 : 0);
91
+ if (argc > 2) {
92
+ throw new ArgumentError(`wrong number of arguments (given ${argc}, expected 1..2)`);
93
+ }
94
+ const hash = receiver;
95
+ const isMap = !plain && hash instanceof Map;
96
+ if (!(isMap ? hash.has(key) : hasKey(hash, key))) {
97
+ if (blockGiven) {
98
+ return rest[rest.length - 1](key);
99
+ }
100
+ else if (argc === 1) {
101
+ throw new KeyError(`key not found: ${strEllipsize(rbInspect(key), 65)}`, {
102
+ receiver: hash,
103
+ key,
104
+ });
105
+ }
106
+ else {
107
+ return rest[0];
108
+ }
109
+ }
110
+ return isMap ? hash.get(key) : hash[key];
111
+ }
112
+ /**
113
+ * Ruby `Hash#key?` / `#has_key?` (`vendor/ruby/v3.3.11/hash.c:3671`
114
+ * `rb_hash_has_key`) — membership, which for a stored `nil` or `false` is the
115
+ * question `hash[key] !== undefined` cannot answer. A receiver that is not a
116
+ * Hash and defines `isKey` answers through it, as Ruby sends `key?` to the
117
+ * receiver: `values.key?(name)`
118
+ * (`activemodel/lib/active_model/attribute_set/builder.rb:33`) is
119
+ * `ActiveRecord::Result::IndexedRow#key?` when `values` is one. `fetch`,
120
+ * `keys` and `eachKey` dispatch the same way. An `undefined`-valued property of
121
+ * a plain object is an absent key: Ruby's stored `nil` is `null`, and a caller
122
+ * forwarding an absent keyword writes `{ name: undefined }`. That holds for a
123
+ * bare object only, with `Object.prototype` or no prototype: a class instance
124
+ * and a `Map` answer for the entry they store. `keys`, `eachKey` and the
125
+ * iterating readers still enumerate the property.
126
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#key?` (`vendor/ruby/v3.3.11/hash.c:3671`).
127
+ */
128
+ export function hasKey(hash, key) {
129
+ /* `vendor/ruby/v3.3.11/hash.c:3671` `rb_hash_has_key` reads the hash table through
130
+ `hash_stlike_lookup`, never an ancestor: a Ruby Hash has no prototype
131
+ chain, so `"toString" in {}` is an answer Ruby never gives. */
132
+ const proto = Object.getPrototypeOf(hash);
133
+ if (proto === Object.prototype || proto === null) {
134
+ return Object.hasOwn(hash, key) && hash[key] !== undefined;
135
+ }
136
+ const own = ownMethod(hash, "isKey");
137
+ if (own)
138
+ return own.call(hash, key);
139
+ if (hash instanceof Map)
140
+ return hash.has(key);
141
+ return Object.hasOwn(hash, key);
142
+ }
143
+ /**
144
+ * Ruby `Hash#keys` (`vendor/ruby/v3.3.11/hash.c:3584` `rb_hash_keys`): a new Array
145
+ * of the keys, in insertion order.
146
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#keys` (`vendor/ruby/v3.3.11/hash.c:3584`).
147
+ */
148
+ export function keys(hash) {
149
+ if (hash instanceof Map)
150
+ return [...hash.keys()];
151
+ const own = ownMethod(hash, "keys");
152
+ if (own)
153
+ return own.call(hash);
154
+ const proto = Object.getPrototypeOf(hash);
155
+ if (proto !== Object.prototype && proto !== null) {
156
+ const reader = hash.keys;
157
+ if (Array.isArray(reader))
158
+ return reader;
159
+ }
160
+ return Object.keys(hash);
161
+ }
162
+ /**
163
+ * Ruby `Hash#include?` (`vendor/ruby/v3.3.11/hash.c:7255`), which MRI defines onto the
164
+ * same `rb_hash_has_key` body as `key?` and `has_key?`.
165
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#include?` (`vendor/ruby/v3.3.11/hash.c:7255`).
166
+ */
167
+ export const isInclude = hasKey;
168
+ const ELLIPSIS = "...";
169
+ /**
170
+ * `rb_str_ellipsize` (`vendor/ruby/v3.3.11/string.c:11027`), the ASCII-compatible arm
171
+ * `rb_hash_fetch_m` reaches with `len` 65: a longer description keeps its first
172
+ * `len - 3` characters and ends in the ellipsis, so the whole is `len` wide.
173
+ */
174
+ function strEllipsize(str, len) {
175
+ if (len >= str.length)
176
+ return str;
177
+ if (len <= ELLIPSIS.length)
178
+ return ELLIPSIS;
179
+ return str.slice(0, len - ELLIPSIS.length) + ELLIPSIS;
180
+ }
181
+ /** @noRailsEquivalent PERMANENT — Ruby core `Hash#merge` (`vendor/ruby/v3.3.11/hash.c:4144`). */
182
+ export function merge(hash, ...others) {
183
+ return update(dup(hash), ...others);
184
+ }
185
+ /**
186
+ * MRI's `rb_to_hash_type` (`vendor/ruby/v3.3.11/hash.c:1904`, `to_hash` at `:1909`), the implicit
187
+ * conversion `rb_hash_update_call` (`vendor/ruby/v3.3.11/hash.c:3960`) applies to
188
+ * each argument: a Hash is itself, anything else is asked for `to_hash`, and
189
+ * one that does not answer it raises `TypeError` (`rb_convert_type_with_id`).
190
+ *
191
+ * @noRailsEquivalent PERMANENT
192
+ */
193
+ export function rbToHashType(hash) {
194
+ if (hash instanceof Map || isPlainHash(hash))
195
+ return hash;
196
+ const own = hash == null ? undefined : ownMethod(hash, "toHash");
197
+ if (!own)
198
+ throw new TypeError(`no implicit conversion of ${rbBuiltinClassName(hash)} into Hash`);
199
+ return own.call(hash);
200
+ }
201
+ /** @noRailsEquivalent PERMANENT — Ruby core `Hash#update` (`vendor/ruby/v3.3.11/hash.c:4028`). */
202
+ export function update(hash, ...others) {
203
+ const block = rbBlockGivenP(others[others.length - 1])
204
+ ? others.pop()
205
+ : undefined;
206
+ for (const arg of others) {
207
+ const other = rbToHashType(arg);
208
+ for (const [key, value] of other instanceof Map ? other : Object.entries(other)) {
209
+ if (hash instanceof Map) {
210
+ hash.set(key, block !== undefined && hash.has(key) ? block(key, hash.get(key), value) : value);
211
+ }
212
+ else {
213
+ hashAset(hash, key, block !== undefined && hasKey(hash, key) ? block(key, hash[key], value) : value);
214
+ }
215
+ }
216
+ }
217
+ return hash;
218
+ }
219
+ /**
220
+ * Ruby `Hash#merge!` (`vendor/ruby/v3.3.11/hash.c:7247`), which MRI defines onto the
221
+ * same `rb_hash_update` body as `update`, conflict-block arm included.
222
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#merge!` (`vendor/ruby/v3.3.11/hash.c:4028`).
223
+ */
224
+ export const mergeBang = update;
225
+ /**
226
+ * Ruby `Hash#replace` (`vendor/ruby/v3.3.11/hash.c:2967` `rb_hash_replace`) — empties
227
+ * the receiver, copies `hash2`'s entries into it, and returns the receiver.
228
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#replace` (`vendor/ruby/v3.3.11/hash.c:2967`).
229
+ */
230
+ export function hashReplace(hash, hash2) {
231
+ if (Object.isFrozen(hash)) {
232
+ throw new FrozenError(`can't modify frozen Hash: ${rbInspect(hash)}`, { receiver: hash });
233
+ }
234
+ if (hash === hash2)
235
+ return hash;
236
+ if (hash instanceof Map) {
237
+ hash.clear();
238
+ }
239
+ else {
240
+ for (const key of Object.keys(hash))
241
+ delete hash[key];
242
+ }
243
+ if (hash2 instanceof Map || hash instanceof Map) {
244
+ for (const [key, value] of hash2 instanceof Map ? hash2 : Object.entries(hash2)) {
245
+ hashAset(hash, key, value);
246
+ }
247
+ }
248
+ else {
249
+ Object.assign(hash, hash2);
250
+ }
251
+ return hash;
252
+ }
253
+ /**
254
+ * An Array receiver takes `Array#delete` (`vendor/ruby/v3.3.11/array.c:3973`), as Ruby's
255
+ * `delete` dispatches on the receiver.
256
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#delete` (`vendor/ruby/v3.3.11/hash.c:2441`).
257
+ */
258
+ export function hashDelete(hash, key, block) {
259
+ if (Array.isArray(hash))
260
+ return aryDelete(hash, key, block) ?? null;
261
+ if (hash instanceof Map) {
262
+ if (hash.has(key)) {
263
+ const val = hash.get(key);
264
+ hash.delete(key);
265
+ return val;
266
+ }
267
+ }
268
+ else {
269
+ if (Object.isFrozen(hash)) {
270
+ throw new FrozenError(`can't modify frozen Hash: ${rbInspect(hash)}`, { receiver: hash });
271
+ }
272
+ if (Object.hasOwn(hash, key)) {
273
+ const val = hash[key];
274
+ delete hash[key];
275
+ return val;
276
+ }
277
+ }
278
+ if (block) {
279
+ return block(key);
280
+ }
281
+ else {
282
+ return null;
283
+ }
284
+ }
285
+ /**
286
+ * Ruby `Hash#clear` (`rb_hash_clear`, `vendor/ruby/v3.3.11/hash.c:2868`), which
287
+ * raises `FrozenError` through `rb_hash_modify_check` on a frozen receiver.
288
+ *
289
+ * @noRailsEquivalent PERMANENT
290
+ */
291
+ export function hashClear(hash) {
292
+ if (Object.isFrozen(hash)) {
293
+ throw new FrozenError(`can't modify frozen Hash: ${rbInspect(hash)}`, { receiver: hash });
294
+ }
295
+ if (hash instanceof Map)
296
+ hash.clear();
297
+ else
298
+ for (const key of Object.keys(hash))
299
+ delete hash[key];
300
+ return hash;
301
+ }
302
+ /**
303
+ * Ruby `Hash#[]` (`vendor/ruby/v3.3.11/hash.c:2121` `rb_hash_aref`) — the stored
304
+ * value, or `nil` when the key is absent, whichever hash it is given. A
305
+ * receiver that is not a Hash is sent its own `[]`, which it must spell `get`,
306
+ * the conventions table's default spelling for the operator. A miss goes to
307
+ * `rb_hash_default_value` (`vendor/ruby/v3.3.11/hash.c:2068`): a `Hash` answers
308
+ * its `default`, and a plain object, which has no default seat, answers `nil`.
309
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#[]` (`vendor/ruby/v3.3.11/hash.c:2121`).
310
+ */
311
+ export function hashAref(hash, key) {
312
+ const proto = Object.getPrototypeOf(hash);
313
+ if (proto !== Object.prototype) {
314
+ const own = ownMethod(hash, "get");
315
+ if (own)
316
+ return own.call(hash, key);
317
+ if (hash instanceof Map) {
318
+ if (hash.has(key))
319
+ return hash.get(key);
320
+ return hash instanceof Hash ? (hash.default(key) ?? null) : null;
321
+ }
322
+ if (hasKey(hash, key))
323
+ return hash[key];
324
+ return null;
325
+ }
326
+ if (Object.hasOwn(hash, key))
327
+ return hash[key];
328
+ return null;
329
+ }
330
+ /**
331
+ * Ruby `Hash#[]=` (`vendor/ruby/v3.3.11/hash.c:2018` `rb_hash_aset`) — stores the
332
+ * pair and returns the value, as the assignment expression does. A receiver
333
+ * that is not a Hash is sent its own `[]=`, spelled `set`.
334
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#[]=` (`vendor/ruby/v3.3.11/hash.c:2018`).
335
+ */
336
+ export function hashAset(hash, key, val) {
337
+ const own = ownMethod(hash, "set");
338
+ if (own) {
339
+ own.call(hash, key, val);
340
+ return val;
341
+ }
342
+ if (hash instanceof Map) {
343
+ hash.set(key, val);
344
+ return val;
345
+ }
346
+ if (Object.isFrozen(hash)) {
347
+ throw new FrozenError(`can't modify frozen Hash: ${rbInspect(hash)}`, { receiver: hash });
348
+ }
349
+ if (key === "__proto__") {
350
+ Object.defineProperty(hash, key, {
351
+ value: val,
352
+ writable: true,
353
+ enumerable: true,
354
+ configurable: true,
355
+ });
356
+ }
357
+ else {
358
+ hash[key] = val;
359
+ }
360
+ return val;
361
+ }
362
+ /**
363
+ * Ruby `Hash#delete_if` (`vendor/ruby/v3.3.11/hash.c:2564` `rb_hash_delete_if`) —
364
+ * MUTATES the receiver, dropping every pair the block answers truthily for,
365
+ * and returns it.
366
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#delete_if` (`vendor/ruby/v3.3.11/hash.c:2564`).
367
+ */
368
+ export function deleteIf(hash, block) {
369
+ for (const key of Object.keys(hash)) {
370
+ const rejected = block(key, hash[key]);
371
+ if (rejected != null && rejected !== false)
372
+ delete hash[key];
373
+ }
374
+ return hash;
375
+ }
376
+ /**
377
+ * Ruby `Hash#keep_if` (`vendor/ruby/v3.3.11/hash.c:2844` `rb_hash_keep_if`) — the
378
+ * inverse of `delete_if`: MUTATES the receiver, dropping every pair the block
379
+ * answers falsily for (`keep_if_i`, `hash.c:2757`), and returns it.
380
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#keep_if` (`vendor/ruby/v3.3.11/hash.c:2844`).
381
+ */
382
+ export function keepIf(hash, block) {
383
+ for (const key of Object.keys(hash)) {
384
+ const kept = block(key, hash[key]);
385
+ if (kept == null || kept === false)
386
+ delete hash[key];
387
+ }
388
+ return hash;
389
+ }
390
+ /**
391
+ * Ruby `Hash#reject` (`vendor/ruby/v3.3.11/hash.c:2626` `rb_hash_reject`) — the
392
+ * non-mutating twin: `delete_if` over a dup.
393
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#reject` (`vendor/ruby/v3.3.11/hash.c:2626`).
394
+ */
395
+ export function reject(hash, block) {
396
+ return deleteIf(dup(hash), block);
397
+ }
398
+ /**
399
+ * The arms share one body.
400
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#each_pair` (`vendor/ruby/v3.3.11/hash.c:3149`).
401
+ */
402
+ export function eachPair(hash, block) {
403
+ const own = ownMethod(hash, "each");
404
+ if (own) {
405
+ own.call(hash, (...args) => args.length === 1 && Array.isArray(args[0])
406
+ ? block(args[0][0], args[0][1])
407
+ : block(...args));
408
+ return hash;
409
+ }
410
+ if (hash instanceof Map) {
411
+ for (const [key, value] of hash)
412
+ block(key, value);
413
+ return hash;
414
+ }
415
+ for (const key of Object.keys(hash)) {
416
+ block(key, hash[key]);
417
+ }
418
+ return hash;
419
+ }
420
+ /**
421
+ * The arms share one body.
422
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#each_value` (`vendor/ruby/v3.3.11/hash.c:3060`).
423
+ */
424
+ export function eachValue(receiver, block) {
425
+ const own = ownMethod(receiver, "eachValue");
426
+ if (own)
427
+ return block ? own.call(receiver, block) : own.call(receiver);
428
+ const hash = receiver;
429
+ if (!block) {
430
+ return new Enumerator({ eachValue: (block) => eachValue(hash, block) }, "eachValue", []);
431
+ }
432
+ if (hash instanceof Map) {
433
+ for (const value of hash.values())
434
+ block(value);
435
+ return hash;
436
+ }
437
+ for (const key of Object.keys(hash)) {
438
+ block(hash[key]);
439
+ }
440
+ return hash;
441
+ }
442
+ /**
443
+ * The arms share one body.
444
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#each_key` (`vendor/ruby/v3.3.11/hash.c:3098`).
445
+ */
446
+ export function eachKey(hash, block) {
447
+ const own = ownMethod(hash, "eachKey");
448
+ if (own)
449
+ return block ? own.call(hash, block) : own.call(hash);
450
+ if (!block)
451
+ return keys(hash);
452
+ for (const key of keys(hash)) {
453
+ block(key);
454
+ }
455
+ return hash;
456
+ }
457
+ /**
458
+ * Ruby `Hash#transform_values!` (`vendor/ruby/v3.3.11/hash.c:3398`
459
+ * `rb_hash_transform_values_bang`): each value replaced in place by the
460
+ * block's result, answering the receiver.
461
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#transform_values!` (`vendor/ruby/v3.3.11/hash.c:3398`).
462
+ */
463
+ export function transformValuesBang(hash, block) {
464
+ if (hash instanceof Map) {
465
+ const set = hash instanceof Hash ? Hash.prototype.set : Map.prototype.set;
466
+ for (const [key, value] of [...hash]) {
467
+ set.call(hash, key, block(value));
468
+ }
469
+ return hash;
470
+ }
471
+ for (const key of Object.keys(hash)) {
472
+ hash[key] = block(hash[key]);
473
+ }
474
+ return hash;
475
+ }
476
+ /** @noRailsEquivalent PERMANENT — Ruby core `Hash#transform_values` (`vendor/ruby/v3.3.11/hash.c:3366`). */
477
+ export function transformValues(hash, block) {
478
+ const own = ownMethod(hash, "transformValues");
479
+ if (own)
480
+ return own.call(hash, block);
481
+ if (hash instanceof Map) {
482
+ const override = hash.transformValues;
483
+ if (typeof override === "function") {
484
+ return override.call(hash, block);
485
+ }
486
+ const result = new Hash();
487
+ for (const [key, value] of hash) {
488
+ result.set(key, block(value));
489
+ }
490
+ return result;
491
+ }
492
+ /* `rb_hash_transform_values` (`vendor/ruby/v3.3.11/hash.c:3366`) builds the new hash
493
+ with `rb_hash_new`, which has no ancestors: `__proto__` is an ordinary key
494
+ there, where `result["__proto__"] = v` on a plain `{}` reaches
495
+ Object.prototype's setter and stores nothing. */
496
+ const result = Object.create(null);
497
+ for (const key of Object.keys(hash)) {
498
+ result[key] = block(hash[key]);
499
+ }
500
+ return result;
501
+ }
502
+ /** @noRailsEquivalent PERMANENT — Ruby core `Hash#slice` (`vendor/ruby/v3.3.11/hash.c:2651`). */
503
+ export function slice(hash, ...keys) {
504
+ if (hash instanceof Map) {
505
+ const result = new Hash();
506
+ for (const key of keys) {
507
+ if (hash.has(key))
508
+ result.set(key, hash.get(key));
509
+ }
510
+ return result;
511
+ }
512
+ const result = Object.create(null);
513
+ for (const key of keys) {
514
+ if (hasKey(hash, key))
515
+ result[key] = hash[key];
516
+ }
517
+ return result;
518
+ }
519
+ /** @noRailsEquivalent PERMANENT — Ruby core `Hash#except` (`vendor/ruby/v3.3.11/hash.c:2683`). */
520
+ export function except(receiver, ...keys) {
521
+ const own = ownMethod(receiver, "except");
522
+ if (own)
523
+ return own.call(receiver, ...keys);
524
+ const hash = receiver;
525
+ const result = hashDupWithCompareById(hash);
526
+ for (const key of keys) {
527
+ hashDelete(result, key);
528
+ }
529
+ return result;
530
+ }
531
+ /**
532
+ * `rb_hash_values_at` pushes `rb_hash_aref(hash, argv[i])` for each key, so the
533
+ * arms share one body over the rest parameter.
534
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#values_at` (`vendor/ruby/v3.3.11/hash.c:2713`).
535
+ */
536
+ export function valuesAt(hash, ...keys) {
537
+ if (hash instanceof Map)
538
+ return keys.map((key) => (hash.has(key) ? hash.get(key) : null));
539
+ return keys.map((key) => (Object.hasOwn(hash, key) ? hash[key] : null));
540
+ }
541
+ /**
542
+ * Ruby `Hash#size` (`vendor/ruby/v3.3.11/hash.c:3002` `rb_hash_size`), and
543
+ * `Array#size` (`vendor/ruby/v3.3.11/array.c:2671` `rb_ary_length`): the number of
544
+ * pairs, or of elements.
545
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#size` (`vendor/ruby/v3.3.11/hash.c:3002`).
546
+ */
547
+ export function size(hash) {
548
+ const own = ownMethod(hash, "size");
549
+ if (own)
550
+ return own.call(hash);
551
+ if (hash instanceof Map || hash instanceof Set)
552
+ return hash.size;
553
+ if (Array.isArray(hash))
554
+ return hash.length;
555
+ return Object.keys(hash).length;
556
+ }
557
+ /**
558
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#dup` (`vendor/ruby/v3.3.11/object.c:591`).
559
+ */
560
+ export function dup(hash) {
561
+ if (!(hash instanceof Hash)) {
562
+ return Object.assign(Object.create(null), hash);
563
+ }
564
+ return hashDup(hash, hash.constructor);
565
+ }
566
+ const RHASH_PASS_AS_KEYWORDS = new WeakSet();
567
+ function rbCheckTypeHash(x) {
568
+ const klass = rbObjClass(x);
569
+ if (klass !== Hash && !(typeof klass === "function" && klass.prototype instanceof Hash)) {
570
+ throw new TypeError(`wrong argument type ${rbBuiltinClassName(x)} (expected Hash)`);
571
+ }
572
+ }
573
+ /**
574
+ * Ruby `Hash.ruby2_keywords_hash?` (`vendor/ruby/v3.3.11/hash.c:1952`
575
+ * `rb_hash_s_ruby2_keywords_hash_p`): whether this hash object is flagged to
576
+ * be passed as keywords. The flag is MRI's `RHASH_PASS_AS_KEYWORDS`
577
+ * (`vendor/ruby/v3.3.11/internal/hash.h:23`), a bit in the hash's own header
578
+ * and no entry of the hash, so no key enumeration or serializer sees it.
579
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash.ruby2_keywords_hash?` (`vendor/ruby/v3.3.11/hash.c:1952`).
580
+ */
581
+ export function rbHashSRuby2KeywordsHashP(hash) {
582
+ rbCheckTypeHash(hash);
583
+ return RHASH_PASS_AS_KEYWORDS.has(hash);
584
+ }
585
+ /**
586
+ * Ruby `Hash.ruby2_keywords_hash` (`vendor/ruby/v3.3.11/hash.c:1974`
587
+ * `rb_hash_s_ruby2_keywords_hash`): a duplicate of the hash carrying the
588
+ * flag. The argument itself is left as it was. Both functions open with
589
+ * `Check_Type(hash, T_HASH)` (`rb_check_type`,
590
+ * `vendor/ruby/v3.3.11/error.c:1251`). MRI's `compare_by_identity` arm for an
591
+ * empty hash (`hash.c:1978-1980`) restores a table type its `hash_copy` drops
592
+ * for an empty table; `hashDup` here carries `compare_by_identity` whatever
593
+ * the size, so the copy already has it.
594
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash.ruby2_keywords_hash` (`vendor/ruby/v3.3.11/hash.c:1974`).
595
+ */
596
+ export function rbHashSRuby2KeywordsHash(hash) {
597
+ rbCheckTypeHash(hash);
598
+ const tmp = dup(hash);
599
+ RHASH_PASS_AS_KEYWORDS.add(tmp);
600
+ return tmp;
601
+ }
602
+ /**
603
+ * `hash_dup_with_compare_by_id` (`vendor/ruby/v3.3.11/hash.c:1563`): an
604
+ * `rb_cHash` allocation holding a `hash_copy` of the table with its type. A
605
+ * plain-object Hash copies into an ancestor-less object, in which `__proto__`
606
+ * stays an ordinary key.
607
+ */
608
+ function hashDupWithCompareById(hash) {
609
+ if (!(hash instanceof Map)) {
610
+ return Object.assign(Object.create(null), hash);
611
+ }
612
+ const dup = new Hash();
613
+ if (hash instanceof Hash && hash.isCompareByIdentity())
614
+ dup.compareByIdentity();
615
+ for (const [key, value] of hash) {
616
+ dup.set(key, value);
617
+ }
618
+ return dup;
619
+ }
620
+ /**
621
+ * `hash_dup` (`vendor/ruby/v3.3.11/hash.c:1576`): a `klass` allocation holding a
622
+ * `hash_copy` of the table, which is not written through `klass`'s `[]=`.
623
+ */
624
+ function hashDup(hash, klass) {
625
+ const ret = new klass();
626
+ const defaultProc = hash.defaultProc();
627
+ if (defaultProc)
628
+ ret.setDefaultProc(defaultProc);
629
+ else
630
+ ret.setDefault(hash.default());
631
+ if (hash.isCompareByIdentity())
632
+ ret.compareByIdentity();
633
+ for (const [key, value] of hash) {
634
+ Hash.prototype.set.call(ret, key, value);
635
+ }
636
+ return ret;
637
+ }
638
+ /**
639
+ * A Ruby `Hash` carrying the `default` / `default_proc` seat a plain JS object
640
+ * has nowhere to put: `Hash.new(obj)` stores a value returned for every miss,
641
+ * `Hash.new { |hash, key| … }` stores a proc run on every miss — the one that
642
+ * lets `hash[key]` populate the hash as it reads it. It subclasses `Map`
643
+ * because Ruby's key equality is `eql?`, not string coercion. Which features
644
+ * make a Ruby Hash a `Hash` rather than a plain object is in the README,
645
+ * § "When a Ruby Hash is a `Hash` and when it is an object".
646
+ *
647
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash` (`vendor/ruby/v3.3.11/hash.c:7182`).
648
+ */
649
+ export class Hash extends Map {
650
+ #default;
651
+ #defaultProc;
652
+ #frozen = false;
653
+ #eqlKeys = new Map();
654
+ #stHash = new WeakMap();
655
+ #identhash = false;
656
+ #binaryKeys = false;
657
+ #iterLev = 0;
658
+ /**
659
+ * @noRailsEquivalent PERMANENT — Ruby core `Class#allocate` (`vendor/ruby/v3.3.11/object.c:2066`).
660
+ */
661
+ static allocate() {
662
+ return new this();
663
+ }
664
+ /**
665
+ * `Hash.new` (`vendor/ruby/v3.3.11/hash.c:1782` `rb_hash_initialize`): a block is
666
+ * the default_proc, an argument the default value, neither is `nil`. A block
667
+ * is a single trailing function argument, the spelling `fetch` uses, and a
668
+ * block beside a default is `rb_check_arity(argc, 0, 0)`'s ArgumentError.
669
+ *
670
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash.new` (`vendor/ruby/v3.3.11/hash.c:1782`).
671
+ */
672
+ constructor(ifnone, block) {
673
+ super();
674
+ if (block !== undefined) {
675
+ throw new ArgumentError("wrong number of arguments (given 1, expected 0)");
676
+ }
677
+ else if (typeof ifnone === "function") {
678
+ this.setDefaultProc(ifnone);
679
+ }
680
+ else if (ifnone !== undefined) {
681
+ this.setDefault(ifnone);
682
+ }
683
+ }
684
+ /**
685
+ * `Hash#[]` (`vendor/ruby/v3.3.11/hash.c:2121` `rb_hash_aref`) — a miss goes to
686
+ * `rb_hash_default_value` (`hash.c:2068`), which runs the default_proc with
687
+ * the missing key.
688
+ *
689
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#[]` (`vendor/ruby/v3.3.11/hash.c:2121`).
690
+ */
691
+ /**
692
+ * `Object#freeze` (`vendor/ruby/v3.3.11/object.c:1284` `rb_obj_freeze`), which
693
+ * `Hash#freeze` (`vendor/ruby/v3.3.11/hash.c:107`) is. `Object.freeze` cannot serve:
694
+ * it seals a JS object's properties, and a `Map`'s entries are not
695
+ * properties, so the seat is the `FL_FREEZE` flag `rb_hash_modify_check`
696
+ * reads.
697
+ *
698
+ * @noRailsEquivalent PERMANENT — Ruby core `Object#freeze` (`vendor/ruby/v3.3.11/object.c:1284`).
699
+ */
700
+ freeze() {
701
+ this.#frozen = true;
702
+ return this;
703
+ }
704
+ /**
705
+ * `Object#frozen?` (`vendor/ruby/v3.3.11/object.c:1301` `rb_obj_frozen_p`). Ruby's
706
+ * `?` predicate suffix is `is` here, per the conventions.
707
+ *
708
+ * @noRailsEquivalent PERMANENT — Ruby core `Object#frozen?` (`vendor/ruby/v3.3.11/object.c:1301`).
709
+ */
710
+ isFrozen() {
711
+ return this.#frozen;
712
+ }
713
+ /**
714
+ * `rb_hash_modify_check` (`vendor/ruby/v3.3.11/hash.c:1602`), which every mutator
715
+ * calls first: `rb_check_frozen` raises `FrozenError` naming the receiver's
716
+ * class and `inspect`.
717
+ */
718
+ modifyCheck() {
719
+ if (this.#frozen) {
720
+ throw new FrozenError(`can't modify frozen ${this.constructor.name}: ${rbInspect(this)}`, {
721
+ receiver: this,
722
+ });
723
+ }
724
+ }
725
+ /**
726
+ * `Hash#[]=` (`vendor/ruby/v3.3.11/hash.c:2018` `rb_hash_aset`), whose
727
+ * `rb_hash_modify` goes through `rb_hash_modify_check` (`hash.c:1623`).
728
+ *
729
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#[]=` (`vendor/ruby/v3.3.11/hash.c:2018`).
730
+ */
731
+ set(key, value) {
732
+ this.modifyCheck();
733
+ const stored = this.hashStlikeLookup(key);
734
+ if (stored === key && !this.#identhash && isObjectKey(key) && !super.has(key)) {
735
+ const h = rbHash(key);
736
+ if (key instanceof Uint8Array)
737
+ this.#binaryKeys = true;
738
+ this.#stHash.set(key, h);
739
+ const bucket = this.#eqlKeys.get(h);
740
+ if (bucket)
741
+ bucket.push(key);
742
+ else
743
+ this.#eqlKeys.set(h, [key]);
744
+ }
745
+ return super.set(stored, value);
746
+ }
747
+ /**
748
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#include?` (`vendor/ruby/v3.3.11/hash.c:7255`, `rb_hash_has_key` `:3671`).
749
+ */
750
+ isInclude(key) {
751
+ return this.has(key);
752
+ }
753
+ /**
754
+ * `Hash#key?` (`vendor/ruby/v3.3.11/hash.c:3671` `rb_hash_has_key`), a lookup by
755
+ * the key's `hash` / `eql?`.
756
+ *
757
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#key?` (`vendor/ruby/v3.3.11/hash.c:3671`).
758
+ */
759
+ has(key) {
760
+ return super.has(this.hashStlikeLookup(key));
761
+ }
762
+ /**
763
+ * `Hash#has_value?` (`vendor/ruby/v3.3.11/hash.c:3697` `rb_hash_has_value`):
764
+ * `rb_hash_search_value` (`:3680`) compares each stored value with `==`.
765
+ *
766
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#has_value?` (`vendor/ruby/v3.3.11/hash.c:3697`).
767
+ */
768
+ hasValue(val) {
769
+ for (const value of super.values()) {
770
+ if (rbEqual(value, val))
771
+ return true;
772
+ }
773
+ return false;
774
+ }
775
+ /**
776
+ * `Hash#key` (`vendor/ruby/v3.3.11/hash.c:2354` `rb_hash_key`): the key of the
777
+ * first entry whose value is `==` to `value` (`key_i`, `:2329`), else `nil`.
778
+ *
779
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#key` (`vendor/ruby/v3.3.11/hash.c:2354`).
780
+ */
781
+ key(value) {
782
+ for (const [key, val] of super.entries()) {
783
+ if (rbEqual(val, value))
784
+ return key;
785
+ }
786
+ return null;
787
+ }
788
+ /**
789
+ * The stored key `eql?` to `key`, found by `hash_stlike_lookup`
790
+ * (`vendor/ruby/v3.3.11/hash.c:2084`) through the `hash` / `eql?` pair
791
+ * (`rb_any_hash`, `hash.c:241`; `rb_any_cmp`, `hash.c:126`). A JS
792
+ * `Map` keys an object by identity, so two equal Arrays would otherwise be
793
+ * two entries. A primitive's identity is already its `eql?`. An identity
794
+ * hash's table type is `identhash` (`vendor/ruby/v3.3.11/hash.c:375`), whose
795
+ * `rb_ident_cmp` is the `Map`'s own comparison. Ruby has one Integer for
796
+ * every magnitude (`rb_int_equal`, `vendor/ruby/v3.3.11/numeric.c:4634`), so a
797
+ * `bigint` that fits a `number` is looked up as that `number`. A binary
798
+ * String, whose seat is a `Uint8Array`, is `eql?` to the 7-bit JS string it
799
+ * spells and hashes as it does (`rb_str_eql`, `vendor/ruby/v3.3.11/string.c:3773`,
800
+ * over `rb_str_comparable`, `string.c:3671`), so either finds the other.
801
+ */
802
+ hashStlikeLookup(key) {
803
+ if (typeof key === "bigint" && Number.isSafeInteger(Number(key)))
804
+ return Number(key);
805
+ if (this.#identhash)
806
+ return key;
807
+ if (typeof key === "string" ? !this.#binaryKeys || super.has(key) : !isObjectKey(key)) {
808
+ return key;
809
+ }
810
+ const stored = this.#eqlKeys.get(rbHash(key))?.find((k) => rbEql(k, key));
811
+ if (stored !== undefined)
812
+ return stored;
813
+ if (key instanceof Uint8Array && key.every((byte) => byte < 0x80)) {
814
+ const str = new TextDecoder().decode(key);
815
+ if (super.has(str))
816
+ return str;
817
+ }
818
+ return key;
819
+ }
820
+ /**
821
+ * `Hash#clear` (`vendor/ruby/v3.3.11/hash.c:1988` `rb_hash_clear`), which also
822
+ * begins with `rb_hash_modify_check`.
823
+ *
824
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#clear` (`vendor/ruby/v3.3.11/hash.c:1988`).
825
+ */
826
+ clear() {
827
+ this.modifyCheck();
828
+ this.#eqlKeys.clear();
829
+ super.clear();
830
+ }
831
+ get(key) {
832
+ const stored = this.hashStlikeLookup(key);
833
+ if (super.has(stored))
834
+ return super.get(stored);
835
+ return this.default(key);
836
+ }
837
+ /**
838
+ * `Hash#default` (`vendor/ruby/v3.3.11/hash.c:2238` `rb_hash_default`), both arms:
839
+ * with no argument the stored default value — `nil` when a default_proc is
840
+ * what is stored — and with a key the proc's result for that key.
841
+ *
842
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#default` (`vendor/ruby/v3.3.11/hash.c:2238`).
843
+ */
844
+ default(...key) {
845
+ if (this.#defaultProc) {
846
+ if (key.length === 0)
847
+ return undefined;
848
+ return this.#defaultProc(this, key[0]);
849
+ }
850
+ return this.#default;
851
+ }
852
+ /**
853
+ * The `JSON.stringify` protocol: a `Map`'s entries are not properties, so
854
+ * without it a Hash stringifies as `{}` where `Hash#to_json`
855
+ * (`vendor/ruby/v3.3.11/ext/json/generator/generator.c:430` `mHash_to_json`)
856
+ * writes each pair under its key's `to_s`, a Symbol's being its name.
857
+ *
858
+ * @noRailsEquivalent PERMANENT
859
+ */
860
+ toJSON() {
861
+ const result = Object.create(null);
862
+ for (const [key, value] of this) {
863
+ result[isSymbol(key) ? symbolToS(key) : String(key)] = value;
864
+ }
865
+ return result;
866
+ }
867
+ toH(block) {
868
+ if (block !== undefined) {
869
+ const h = new Hash();
870
+ for (const [key, value] of this) {
871
+ const pair = block(key, value);
872
+ if (!Array.isArray(pair)) {
873
+ throw new TypeError(`wrong element type ${rbBuiltinClassName(pair)} (expected array)`);
874
+ }
875
+ if (pair.length !== 2) {
876
+ throw new ArgumentError(`element has wrong array length (expected 2, was ${pair.length})`);
877
+ }
878
+ h.set(pair[0], pair[1]);
879
+ }
880
+ return h;
881
+ }
882
+ if (this.constructor === Hash)
883
+ return this;
884
+ if (this.default() == null &&
885
+ !this.defaultProc() &&
886
+ !this.isCompareByIdentity() &&
887
+ [...this.keys()].every((key) => typeof key === "string")) {
888
+ return Object.fromEntries(this);
889
+ }
890
+ return hashDup(this, Hash);
891
+ }
892
+ /**
893
+ * `Hash#default=` (`vendor/ruby/v3.3.11/hash.c:2265` `rb_hash_set_default`), whose
894
+ * `SET_DEFAULT` clears `RHASH_PROC_DEFAULT`. A TS `set` accessor cannot
895
+ * share a name with the `default()` reader, so it takes the conventions'
896
+ * `setX()` spelling.
897
+ *
898
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#default=` (`vendor/ruby/v3.3.11/hash.c:2265`).
899
+ */
900
+ setDefault(value) {
901
+ this.modifyCheck();
902
+ this.#default = value;
903
+ this.#defaultProc = undefined;
904
+ }
905
+ /**
906
+ * `Hash#default_proc` (`vendor/ruby/v3.3.11/hash.c:2285` `rb_hash_default_proc`):
907
+ * the proc only when one is what is stored.
908
+ *
909
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#default_proc` (`vendor/ruby/v3.3.11/hash.c:2285`).
910
+ */
911
+ defaultProc() {
912
+ return this.#defaultProc;
913
+ }
914
+ /**
915
+ * `Hash#default_proc=` (`vendor/ruby/v3.3.11/hash.c:2308`
916
+ * `rb_hash_set_default_proc`): `nil` goes through `SET_DEFAULT`, clearing
917
+ * the proc; anything that is not a Proc is a `TypeError`.
918
+ *
919
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#default_proc=` (`vendor/ruby/v3.3.11/hash.c:2308`).
920
+ */
921
+ setDefaultProc(proc) {
922
+ this.modifyCheck();
923
+ if (proc == null) {
924
+ this.setDefault(undefined);
925
+ return;
926
+ }
927
+ if (typeof proc !== "function") {
928
+ throw new TypeError(`wrong default_proc type ${proc.constructor.name} (expected Proc)`);
929
+ }
930
+ this.#default = undefined;
931
+ this.#defaultProc = proc;
932
+ }
933
+ /**
934
+ * `Hash#delete` (`vendor/ruby/v3.3.11/hash.c:2441` `rb_hash_delete_m`): returns the
935
+ * deleted value, the block's result for a key that was not there, `nil`
936
+ * otherwise. `Map#delete` returns a boolean instead, and a TS override may
937
+ * not narrow a `boolean` return, so the declared return is
938
+ * `MapBoundaryReturn` — the dynamic return Ruby has here.
939
+ *
940
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#delete` (`vendor/ruby/v3.3.11/hash.c:2441`).
941
+ */
942
+ delete(key, block) {
943
+ this.modifyCheck();
944
+ const val = this.deleteEntry(key);
945
+ if (val !== UNDEF)
946
+ return val;
947
+ if (block)
948
+ return block(key);
949
+ return undefined;
950
+ }
951
+ /**
952
+ * `rb_hash_delete_entry` (`vendor/ruby/v3.3.11/hash.c:2383`): the stored
953
+ * value, or `Qundef` for a key that was not there.
954
+ */
955
+ deleteEntry(key) {
956
+ const stored = this.hashStlikeLookup(key);
957
+ if (!super.has(stored))
958
+ return UNDEF;
959
+ const val = super.get(stored);
960
+ this.stDeleteEntry(stored);
961
+ return val;
962
+ }
963
+ /**
964
+ * Removes a stored entry from its bin by the hash the entry was stored
965
+ * under, as `st_table_entry.hash` holds it (`vendor/ruby/v3.3.11/st.c:134`),
966
+ * so a key whose `hash` has changed since is still found.
967
+ */
968
+ stDeleteEntry(stored) {
969
+ super.delete(stored);
970
+ if (!this.#identhash && isObjectKey(stored)) {
971
+ const h = this.#stHash.get(stored);
972
+ const bucket = this.#eqlKeys.get(h);
973
+ bucket.splice(bucket.indexOf(stored), 1);
974
+ if (bucket.length === 0)
975
+ this.#eqlKeys.delete(h);
976
+ }
977
+ }
978
+ /**
979
+ * `Hash#shift` (`vendor/ruby/v3.3.11/hash.c:2492` `rb_hash_shift`): removes
980
+ * the first entry and returns it as a `[key, value]` pair, `nil` for an
981
+ * empty hash, after `rb_hash_modify_check`. The entry is removed directly,
982
+ * with no lookup of its key, as `st_shift` does (`hash.c:2515`). MRI takes
983
+ * it through `rb_hash_foreach` only while the hash is being iterated,
984
+ * because `st_shift` may not run then; a `Map` drops its first entry
985
+ * either way.
986
+ *
987
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#shift` (`vendor/ruby/v3.3.11/hash.c:2492`).
988
+ */
989
+ shift() {
990
+ this.modifyCheck();
991
+ const first = super.entries().next();
992
+ if (!first.done) {
993
+ this.stDeleteEntry(first.value[0]);
994
+ return first.value;
995
+ }
996
+ return undefined;
997
+ }
998
+ /**
999
+ * `Hash#compare_by_identity` (`vendor/ruby/v3.3.11/hash.c:4427`
1000
+ * `rb_hash_compare_by_id`): keys are compared by identity from here on, and
1001
+ * the receiver is returned. The rehash into an `identhash` table keeps every
1002
+ * entry, since two stored keys were never `eql?`, so only the `eql?` index
1003
+ * goes. A JS string is a primitive with no identity apart from its value, so
1004
+ * two equal Strings stay one key where Ruby makes them two.
1005
+ *
1006
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#compare_by_identity` (`vendor/ruby/v3.3.11/hash.c:4427`).
1007
+ */
1008
+ compareByIdentity() {
1009
+ if (this.isCompareByIdentity())
1010
+ return this;
1011
+ this.modifyCheck();
1012
+ if (this.hashIteratingP()) {
1013
+ throw new RuntimeError("compare_by_identity during iteration");
1014
+ }
1015
+ this.#identhash = true;
1016
+ this.#eqlKeys.clear();
1017
+ return this;
1018
+ }
1019
+ /**
1020
+ * `rb_hash_foreach` (`vendor/ruby/v3.3.11/hash.c:1438`), the walk every
1021
+ * yielding Hash method goes through: it raises the receiver's `iter_lev`
1022
+ * for the length of the walk and lowers it in an `ensure`. A `for…of` that
1023
+ * ends, breaks or throws closes the iterator and lowers the level. One left
1024
+ * part-way keeps it raised, as a suspended `hash.each` Enumerator does.
1025
+ *
1026
+ * @noRailsEquivalent PERMANENT — Ruby core `rb_hash_foreach` (`vendor/ruby/v3.3.11/hash.c:1438`).
1027
+ */
1028
+ *[Symbol.iterator]() {
1029
+ if (this.size === 0)
1030
+ return;
1031
+ if (this.#frozen) {
1032
+ yield* super[Symbol.iterator]();
1033
+ }
1034
+ else {
1035
+ this.#iterLev++;
1036
+ try {
1037
+ yield* super[Symbol.iterator]();
1038
+ }
1039
+ finally {
1040
+ this.#iterLev--;
1041
+ }
1042
+ }
1043
+ }
1044
+ /**
1045
+ * `Map#entries`, the pair walk under another name, so it goes through
1046
+ * `rb_hash_foreach` (`vendor/ruby/v3.3.11/hash.c:1438`) as `Hash#each_pair`
1047
+ * does (`hash.c:3149`).
1048
+ *
1049
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#each_pair` (`vendor/ruby/v3.3.11/hash.c:3149`).
1050
+ */
1051
+ entries() {
1052
+ return this[Symbol.iterator]();
1053
+ }
1054
+ /**
1055
+ * `Map#forEach`, walked through `rb_hash_foreach`
1056
+ * (`vendor/ruby/v3.3.11/hash.c:1438`) as `Hash#each_pair` is (`hash.c:3149`).
1057
+ *
1058
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#each_pair` (`vendor/ruby/v3.3.11/hash.c:3149`).
1059
+ */
1060
+ forEach(callbackfn, thisArg) {
1061
+ for (const [key, value] of this)
1062
+ callbackfn.call(thisArg, value, key, this);
1063
+ }
1064
+ /**
1065
+ * `Hash#initialize_copy`, which MRI binds to `rb_hash_replace`
1066
+ * (`vendor/ruby/v3.3.11/hash.c:7190`): the hook `rbObjDup` / `rbObjClone`
1067
+ * dispatch, so a dup holds a copy of the receiver's table.
1068
+ *
1069
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#initialize_copy` (`vendor/ruby/v3.3.11/hash.c:7190`).
1070
+ */
1071
+ initializeCopy(hash) {
1072
+ return this.replace(hash);
1073
+ }
1074
+ /**
1075
+ * `Hash#replace` (`vendor/ruby/v3.3.11/hash.c:2967` `rb_hash_replace`): the
1076
+ * receiver takes `hash2`'s `default` / `default_proc` (`COPY_DEFAULT`) and a
1077
+ * `hash_copy` of its table, which is not written through a subclass's `[]=`.
1078
+ *
1079
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#replace` (`vendor/ruby/v3.3.11/hash.c:2967`).
1080
+ */
1081
+ replace(hash2) {
1082
+ this.modifyCheck();
1083
+ if (this === hash2)
1084
+ return this;
1085
+ if (this.hashIteratingP()) {
1086
+ throw new RuntimeError("can't replace hash during iteration");
1087
+ }
1088
+ const pairs = (Symbol.iterator in hash2 ? [...hash2] : Object.entries(hash2));
1089
+ if (hash2 instanceof Hash) {
1090
+ this.#default = hash2.#default;
1091
+ this.#defaultProc = hash2.#defaultProc;
1092
+ }
1093
+ Hash.prototype.clear.call(this);
1094
+ for (const [key, value] of pairs)
1095
+ Hash.prototype.set.call(this, key, value);
1096
+ return this;
1097
+ }
1098
+ /**
1099
+ * `Hash#merge` (`vendor/ruby/v3.3.11/hash.c:4144` `rb_hash_merge`), the
1100
+ * method a `:merge` send finds; the body is {@link merge}'s. The conflict
1101
+ * block is the trailing argument, marked with {@link block}.
1102
+ *
1103
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#merge` (`vendor/ruby/v3.3.11/hash.c:4144`).
1104
+ */
1105
+ merge(...argv) {
1106
+ return merge(this, ...argv);
1107
+ }
1108
+ /** `hash_iterating_p` (`vendor/ruby/v3.3.11/hash.c:1339`). */
1109
+ hashIteratingP() {
1110
+ return this.#iterLev > 0;
1111
+ }
1112
+ /**
1113
+ * `Hash#compare_by_identity?` (`vendor/ruby/v3.3.11/hash.c:4474`
1114
+ * `rb_hash_compare_by_id_p`).
1115
+ *
1116
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#compare_by_identity?` (`vendor/ruby/v3.3.11/hash.c:4474`).
1117
+ */
1118
+ isCompareByIdentity() {
1119
+ return this.#identhash;
1120
+ }
1121
+ /**
1122
+ * `Hash#each` (`vendor/ruby/v3.3.11/hash.c:7219`), `rb_hash_each_pair`
1123
+ * (`hash.c:3149`): yields the key and the value to a block taking two
1124
+ * parameters (`each_pair_i_fast`) and one `[key, value]` pair otherwise
1125
+ * (`each_pair_i`), and returns the receiver.
1126
+ *
1127
+ * @noRailsEquivalent PERMANENT
1128
+ */
1129
+ each(block) {
1130
+ if (block.length > 1) {
1131
+ for (const [key, value] of super.entries())
1132
+ block(key, value);
1133
+ }
1134
+ else {
1135
+ for (const pair of super.entries())
1136
+ block(pair);
1137
+ }
1138
+ return this;
1139
+ }
1140
+ /**
1141
+ * `Hash#keys` (`vendor/ruby/v3.3.11/hash.c:3584` `rb_hash_keys`): an Array of the
1142
+ * keys, where `Map#keys` is an iterator. A TS override may not narrow that
1143
+ * return, so it declares `MapBoundaryReturn`, the same Map boundary `delete`
1144
+ * meets.
1145
+ *
1146
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#keys` (`vendor/ruby/v3.3.11/hash.c:3584`).
1147
+ */
1148
+ keys() {
1149
+ return [...super.keys()];
1150
+ }
1151
+ /**
1152
+ * `Hash#values` (`vendor/ruby/v3.3.11/hash.c:3628` `rb_hash_values`): an Array of the
1153
+ * values, where `Map#values` is an iterator.
1154
+ *
1155
+ * @noRailsEquivalent PERMANENT — Ruby core `Hash#values` (`vendor/ruby/v3.3.11/hash.c:3628`).
1156
+ */
1157
+ values() {
1158
+ return [...super.values()];
1159
+ }
1160
+ /**
1161
+ * `Hash#length` (`vendor/ruby/v3.3.11/hash.c:3002` `rb_hash_size`).
1162
+ *
1163
+ * @noRailsEquivalent PERMANENT
1164
+ */
1165
+ length() {
1166
+ return this.size;
1167
+ }
1168
+ /**
1169
+ * `Hash#empty?` (`vendor/ruby/v3.3.11/hash.c:3023` `rb_hash_empty_p`).
1170
+ *
1171
+ * @noRailsEquivalent PERMANENT
1172
+ */
1173
+ isEmpty() {
1174
+ return this.size === 0;
1175
+ }
1176
+ /**
1177
+ * `Hash#delete_if` (`vendor/ruby/v3.3.11/hash.c:2564` `rb_hash_delete_if`):
1178
+ * drops every pair the block answers truthily for, and returns the receiver.
1179
+ *
1180
+ * @noRailsEquivalent PERMANENT
1181
+ */
1182
+ deleteIf(block) {
1183
+ this.modifyCheck();
1184
+ for (const [key, value] of this) {
1185
+ const ret = block(key, value);
1186
+ if (ret != null && ret !== false)
1187
+ this.deleteEntry(key);
1188
+ }
1189
+ return this;
1190
+ }
1191
+ /**
1192
+ * `Hash#reject!` (`vendor/ruby/v3.3.11/hash.c:2594` `rb_hash_reject_bang`):
1193
+ * `delete_if`, answering `nil` when nothing was deleted.
1194
+ *
1195
+ * @noRailsEquivalent PERMANENT
1196
+ */
1197
+ rejectBang(block) {
1198
+ this.modifyCheck();
1199
+ const n = this.size;
1200
+ if (!n)
1201
+ return null;
1202
+ this.deleteIf(block);
1203
+ if (n === this.size)
1204
+ return null;
1205
+ return this;
1206
+ }
1207
+ /**
1208
+ * `Hash#keep_if` (`vendor/ruby/v3.3.11/hash.c:2844` `rb_hash_keep_if`): drops
1209
+ * every pair the block answers falsily for (`keep_if_i`, `:2757`).
1210
+ *
1211
+ * @noRailsEquivalent PERMANENT
1212
+ */
1213
+ keepIf(block) {
1214
+ this.modifyCheck();
1215
+ for (const [key, value] of this) {
1216
+ const ret = block(key, value);
1217
+ if (ret == null || ret === false)
1218
+ this.deleteEntry(key);
1219
+ }
1220
+ return this;
1221
+ }
1222
+ /**
1223
+ * `Hash#select!` (`vendor/ruby/v3.3.11/hash.c:2813` `rb_hash_select_bang`):
1224
+ * `keep_if`, answering `nil` when nothing was deleted.
1225
+ *
1226
+ * @noRailsEquivalent PERMANENT
1227
+ */
1228
+ selectBang(block) {
1229
+ this.modifyCheck();
1230
+ const n = this.size;
1231
+ if (!n)
1232
+ return null;
1233
+ this.keepIf(block);
1234
+ if (n === this.size)
1235
+ return null;
1236
+ return this;
1237
+ }
1238
+ /**
1239
+ * `Hash#transform_values!` (`vendor/ruby/v3.3.11/hash.c:3398`
1240
+ * `rb_hash_transform_values_bang`).
1241
+ *
1242
+ * @noRailsEquivalent PERMANENT
1243
+ */
1244
+ transformValuesBang(block) {
1245
+ this.modifyCheck();
1246
+ for (const [key, value] of [...super.entries()]) {
1247
+ super.set(key, block(value));
1248
+ }
1249
+ return this;
1250
+ }
1251
+ /**
1252
+ * `Hash#store` (`vendor/ruby/v3.3.11/hash.c:7177`), `rb_hash_aset`.
1253
+ *
1254
+ * @noRailsEquivalent PERMANENT
1255
+ */
1256
+ store(key, value) {
1257
+ return this.set(key, value);
1258
+ }
1259
+ /**
1260
+ * `Hash#fetch` (`vendor/ruby/v3.3.11/hash.c:2176` `rb_hash_fetch_m`); the body is
1261
+ * {@link fetch}'s.
1262
+ *
1263
+ * @noRailsEquivalent PERMANENT
1264
+ */
1265
+ fetch(key, ...rest) {
1266
+ return fetch(this, key, ...rest);
1267
+ }
1268
+ /**
1269
+ * `Hash#key?` / `#has_key?` (`vendor/ruby/v3.3.11/hash.c:3671` `rb_hash_has_key`).
1270
+ *
1271
+ * @noRailsEquivalent PERMANENT
1272
+ */
1273
+ hasKey(key) {
1274
+ return this.has(key);
1275
+ }
1276
+ /**
1277
+ * `Hash#member?` (`vendor/ruby/v3.3.11/hash.c:7239`), `rb_hash_has_key`.
1278
+ *
1279
+ * @noRailsEquivalent PERMANENT
1280
+ */
1281
+ isMember(key) {
1282
+ return this.has(key);
1283
+ }
1284
+ /**
1285
+ * `Hash#invert` (`vendor/ruby/v3.3.11/hash.c:3900` `rb_hash_invert`): a new bare
1286
+ * Hash mapping each value to its key.
1287
+ *
1288
+ * @noRailsEquivalent PERMANENT
1289
+ */
1290
+ invert() {
1291
+ const h = new Hash();
1292
+ for (const [key, value] of super.entries())
1293
+ h.set(value, key);
1294
+ return h;
1295
+ }
1296
+ /**
1297
+ * `Hash#to_proc` (`vendor/ruby/v3.3.11/hash.c:4752` `rb_hash_to_proc`): a lambda
1298
+ * answering `hash[key]`.
1299
+ *
1300
+ * @noRailsEquivalent PERMANENT
1301
+ */
1302
+ toProc() {
1303
+ return (key) => this.get(key);
1304
+ }
1305
+ /**
1306
+ * `Hash#transform_values` (`vendor/ruby/v3.3.11/hash.c:3366`
1307
+ * `rb_hash_transform_values`): a new Hash with each value replaced by the
1308
+ * block's result.
1309
+ *
1310
+ * @noRailsEquivalent PERMANENT
1311
+ */
1312
+ transformValues(block) {
1313
+ const result = new Hash();
1314
+ for (const [key, value] of super.entries())
1315
+ result.set(key, block(value));
1316
+ return result;
1317
+ }
1318
+ /**
1319
+ * `Hash#update` (`vendor/ruby/v3.3.11/hash.c:4028` `rb_hash_update`); the body is
1320
+ * {@link update}'s.
1321
+ *
1322
+ * @noRailsEquivalent PERMANENT
1323
+ */
1324
+ update(...others) {
1325
+ return update(this, ...others);
1326
+ }
1327
+ /**
1328
+ * `Hash#merge!` (`vendor/ruby/v3.3.11/hash.c:7247`), defined onto `rb_hash_update`.
1329
+ *
1330
+ * @noRailsEquivalent PERMANENT
1331
+ */
1332
+ mergeBang(...others) {
1333
+ return this.update(...others);
1334
+ }
1335
+ /**
1336
+ * `Hash#values_at` (`vendor/ruby/v3.3.11/hash.c:2713` `rb_hash_values_at`): each
1337
+ * key's `rb_hash_aref`, the default included.
1338
+ *
1339
+ * @noRailsEquivalent PERMANENT
1340
+ */
1341
+ valuesAt(...keys) {
1342
+ return keys.map((key) => this.get(key));
1343
+ }
1344
+ /**
1345
+ * `Hash#slice` (`vendor/ruby/v3.3.11/hash.c:2651` `rb_hash_slice`); the body is
1346
+ * {@link slice}'s.
1347
+ *
1348
+ * @noRailsEquivalent PERMANENT
1349
+ */
1350
+ slice(...keys) {
1351
+ return slice(this, ...keys);
1352
+ }
1353
+ /**
1354
+ * `Hash#transform_keys` (`vendor/ruby/v3.3.11/hash.c:3227` `rb_hash_transform_keys`):
1355
+ * a new bare Hash keyed by `hash2`'s mapping, else the block's result, else
1356
+ * the key itself (`transform_keys_hash_i`, `:3166`), or by the block alone
1357
+ * (`transform_keys_i`, `:3182`). The blockless Enumerator arm is not ported.
1358
+ *
1359
+ * @noRailsEquivalent PERMANENT
1360
+ */
1361
+ transformKeys(hash2, block) {
1362
+ if (typeof hash2 === "function")
1363
+ [hash2, block] = [undefined, hash2];
1364
+ const trans = hash2 === undefined
1365
+ ? undefined
1366
+ : rbToHashType(hash2);
1367
+ const result = new Hash();
1368
+ if (trans !== undefined) {
1369
+ for (const [key, value] of super.entries()) {
1370
+ let newKey;
1371
+ if (trans instanceof Map ? trans.has(key) : Object.hasOwn(trans, key)) {
1372
+ newKey = trans instanceof Map ? trans.get(key) : trans[key];
1373
+ }
1374
+ else if (block !== undefined) {
1375
+ newKey = block(key);
1376
+ }
1377
+ else {
1378
+ newKey = key;
1379
+ }
1380
+ result.set(newKey, value);
1381
+ }
1382
+ }
1383
+ else {
1384
+ for (const [key, value] of super.entries())
1385
+ result.set(block(key), value);
1386
+ }
1387
+ return result;
1388
+ }
1389
+ /**
1390
+ * `Hash#transform_keys!` (`vendor/ruby/v3.3.11/hash.c:3267`
1391
+ * `rb_hash_transform_keys_bang`).
1392
+ *
1393
+ * @noRailsEquivalent PERMANENT
1394
+ */
1395
+ transformKeysBang(hash2, block) {
1396
+ if (typeof hash2 === "function")
1397
+ [hash2, block] = [undefined, hash2];
1398
+ const trans = hash2 === undefined
1399
+ ? undefined
1400
+ : rbToHashType(hash2);
1401
+ this.modifyCheck();
1402
+ const pairs = [...super.entries()];
1403
+ const newKeys = new Hash();
1404
+ for (const [key, val] of pairs) {
1405
+ let newKey;
1406
+ if (trans === undefined) {
1407
+ newKey = block(key);
1408
+ }
1409
+ else if (trans instanceof Map ? trans.has(key) : Object.hasOwn(trans, key)) {
1410
+ newKey = trans instanceof Map ? trans.get(key) : trans[key];
1411
+ }
1412
+ else if (block !== undefined) {
1413
+ newKey = block(key);
1414
+ }
1415
+ else {
1416
+ newKey = key;
1417
+ }
1418
+ if (!newKeys.has(key))
1419
+ this.deleteEntry(key);
1420
+ this.set(newKey, val);
1421
+ newKeys.set(newKey, null);
1422
+ }
1423
+ return this;
1424
+ }
1425
+ /**
1426
+ * `Hash#except` (`vendor/ruby/v3.3.11/hash.c:2683` `rb_hash_except`); the body is
1427
+ * {@link except}'s.
1428
+ *
1429
+ * @noRailsEquivalent PERMANENT
1430
+ */
1431
+ except(...keys) {
1432
+ return except(this, ...keys);
1433
+ }
1434
+ /**
1435
+ * `Hash#to_a` (`vendor/ruby/v3.3.11/hash.c:3428` `rb_hash_to_a`).
1436
+ *
1437
+ * @noRailsEquivalent PERMANENT
1438
+ */
1439
+ toA() {
1440
+ return [...this];
1441
+ }
1442
+ /**
1443
+ * `Hash#to_hash` (`vendor/ruby/v3.3.11/hash.c:3497` `rb_hash_to_hash`): the
1444
+ * receiver itself.
1445
+ *
1446
+ * @noRailsEquivalent PERMANENT
1447
+ */
1448
+ toHash() {
1449
+ return this;
1450
+ }
1451
+ /**
1452
+ * `Hash#assoc` (`vendor/ruby/v3.3.11/hash.c:4193` `rb_hash_assoc`): the stored
1453
+ * key and its value for `key`, else `nil`.
1454
+ *
1455
+ * @noRailsEquivalent PERMANENT
1456
+ */
1457
+ assoc(key) {
1458
+ const stored = this.hashStlikeLookup(key);
1459
+ if (!super.has(stored))
1460
+ return null;
1461
+ return [stored, super.get(stored)];
1462
+ }
1463
+ /**
1464
+ * `Hash#dig` (`vendor/ruby/v3.3.11/hash.c:4627` `rb_hash_dig`): `self[key]`,
1465
+ * then `rb_obj_dig` (`vendor/ruby/v3.3.11/object.c:3906`) over the rest, which
1466
+ * answers `nil` through a `nil` and sends `dig` to anything else.
1467
+ *
1468
+ * @noRailsEquivalent PERMANENT
1469
+ */
1470
+ dig(key, ...rest) {
1471
+ const obj = this.get(key);
1472
+ if (rest.length === 0)
1473
+ return obj;
1474
+ if (obj == null)
1475
+ return null;
1476
+ const dig = obj.dig;
1477
+ if (typeof dig !== "function") {
1478
+ throw new TypeError(`${rbBuiltinClassName(obj)} does not have #dig method`);
1479
+ }
1480
+ return dig.call(obj, ...rest);
1481
+ }
1482
+ /**
1483
+ * `Hash#fetch_values` (`vendor/ruby/v3.3.11/hash.c:2745`
1484
+ * `rb_hash_fetch_values`): `rb_hash_fetch` for each key.
1485
+ *
1486
+ * @noRailsEquivalent PERMANENT
1487
+ */
1488
+ fetchValues(...argv) {
1489
+ return argv.map((key) => fetch(this, key));
1490
+ }
1491
+ /**
1492
+ * `Hash#rassoc` (`vendor/ruby/v3.3.11/hash.c:4254` `rb_hash_rassoc`): the
1493
+ * first pair whose value is `==` to `obj` (`rassoc_i`), else `nil`.
1494
+ *
1495
+ * @noRailsEquivalent PERMANENT
1496
+ */
1497
+ rassoc(obj) {
1498
+ for (const [key, value] of this) {
1499
+ if (rbEqual(value, obj))
1500
+ return [key, value];
1501
+ }
1502
+ return null;
1503
+ }
1504
+ /**
1505
+ * `Hash#flatten` (`vendor/ruby/v3.3.11/hash.c:4308` `rb_hash_flatten`): the
1506
+ * pairs spliced into one Array, then `flatten!(level - 1)` over it, or a
1507
+ * recursive `flatten!` for a negative level.
1508
+ *
1509
+ * @noRailsEquivalent PERMANENT
1510
+ */
1511
+ flatten(...argv) {
1512
+ if (argv.length) {
1513
+ const level = argv[0];
1514
+ if (level === 0)
1515
+ return this.toA();
1516
+ const ary = [];
1517
+ for (const [key, value] of this)
1518
+ ary.push(key, value);
1519
+ const rest = level - 1;
1520
+ if (rest > 0)
1521
+ return ary.flat(rest);
1522
+ else if (rest < 0)
1523
+ return ary.flat(Infinity);
1524
+ return ary;
1525
+ }
1526
+ const ary = [];
1527
+ for (const [key, value] of this)
1528
+ ary.push(key, value);
1529
+ return ary;
1530
+ }
1531
+ /**
1532
+ * `Hash#compact` (`vendor/ruby/v3.3.11/hash.c:4360` `rb_hash_compact`): a dup
1533
+ * with every `nil` value dropped (`delete_if_nil`).
1534
+ *
1535
+ * @noRailsEquivalent PERMANENT
1536
+ */
1537
+ compact() {
1538
+ const result = hashDup(this, this.constructor);
1539
+ if (this.size) {
1540
+ result.deleteIf((_key, value) => value == null);
1541
+ }
1542
+ return result;
1543
+ }
1544
+ /**
1545
+ * `Hash#compact!` (`vendor/ruby/v3.3.11/hash.c:4385` `rb_hash_compact_bang`).
1546
+ *
1547
+ * @noRailsEquivalent PERMANENT
1548
+ */
1549
+ compactBang() {
1550
+ this.modifyCheck();
1551
+ const n = this.size;
1552
+ if (n) {
1553
+ this.deleteIf((_key, value) => value == null);
1554
+ if (n !== this.size)
1555
+ return this;
1556
+ }
1557
+ return null;
1558
+ }
1559
+ /**
1560
+ * `Hash#deconstruct_keys` (`vendor/ruby/v3.3.11/hash.c:4759`
1561
+ * `rb_hash_deconstruct_keys`): the receiver itself.
1562
+ *
1563
+ * @noRailsEquivalent PERMANENT
1564
+ */
1565
+ deconstructKeys(_keys) {
1566
+ return this;
1567
+ }
1568
+ }
1569
+ function isObjectKey(key) {
1570
+ return typeof key === "object" && key !== null;
1571
+ }
1572
+ //# sourceMappingURL=hash.js.map