@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
@@ -0,0 +1,2195 @@
1
+ /**
2
+ * Ruby-style `include` for mixing module methods into a class.
3
+ *
4
+ * In Ruby, `include SomeModule` copies the module's instance methods
5
+ * onto the including class's method lookup chain. This function does
6
+ * the TypeScript equivalent: assigns each method from the module object
7
+ * onto `klass.prototype`.
8
+ *
9
+ * Mirrors: Ruby's Module#include — vendor/ruby/v3.3.11/eval.c:1139 `rb_mod_include`,
10
+ * backed by vendor/ruby/v3.3.11/class.c:1179 `rb_include_module`.
11
+ *
12
+ * Usage:
13
+ * // Define a module as a plain object of this-typed functions
14
+ * const QueryMethods = {
15
+ * whereBang(this: Relation, opts: any) { ... },
16
+ * orderBang(this: Relation, ...args: any[]) { ... },
17
+ * };
18
+ *
19
+ * // Include it into a class
20
+ * include(Relation, QueryMethods);
21
+ */
22
+ import { methodCacheSerial, rbClearMethodCache } from "./method-cache.js";
23
+ import { ArgumentError } from "./argument-error.js";
24
+ import { abort } from "./process-adapter.js";
25
+ import { NameError } from "./name-error.js";
26
+ import { NoMethodError } from "./no-method-error.js";
27
+ import { autoloadDelete, constGet } from "./variable.js";
28
+ import { temporalTag } from "./temporal-tag.js";
29
+ import { classModule } from "./class-module.js";
30
+ import { rbClassPath, markModuleObject } from "./classpath.js";
31
+ export { classModule };
32
+ import { Enumerable } from "./enumerable.js";
33
+ import { Hash } from "./hash.js";
34
+ import { TypeError } from "./type-error.js";
35
+ import { FrozenError } from "./frozen-error.js";
36
+ import { BigDecimal } from "./big-decimal.js";
37
+ import { Complex } from "./complex.js";
38
+ import { Rational } from "./rational.js";
39
+ import { toI } from "./numeric.js";
40
+ import { FL_SINGLETON, T_ICLASS, TopLevel, classpaths, isPlainHash, rbSetClassPathString, rbAnyToS, rbCBasicObject, rbCClass, rbCDate, rbCNumeric, rbCInteger, rbCFloat, rbModDefineMethod, rbObjClass, rbObjSingletonClass, rbInspect, rbCString, rbCSymbol, rbCTime, rbModAttrReader, rbModAttrWriter, isAbsentHalf, defineAccessorHalf, rbModName, rbModToS, UNDEF_METHOD_TABLES, reopened, rbSeatSuper, superSlots, superSlotFor, _superSlot, } from "./object.js";
41
+ import { isSymbol } from "./symbol.js";
42
+ /**
43
+ * Mirrors: Ruby's Module#const_set — vendor/ruby/v3.3.11/object.c:2545
44
+ * `rb_mod_const_set`, which raises `NameError` for a name that is not a
45
+ * constant name (`id_for_var`, object.c:2220-2240): an uppercase or titlecase
46
+ * letter (`rb_sym_constant_char_p`, vendor/ruby/v3.3.11/symbol.c:218-250), then
47
+ * identifier characters (`is_identchar`, symbol.c:54). It then calls `const_set`
48
+ * (vendor/ruby/v3.3.11/variable.c:3607). Binding a module names it after the
49
+ * owner (variable.c:3648-3668), as it does a class or a `defineModule` plain
50
+ * module: permanently under a named
51
+ * owner, and under an anonymous one with the owner's temporary path, until a
52
+ * named owner re-paths it. `Module#name` and `Module#inspect` read that path.
53
+ * `rb_namespace_p` (variable.c:83) admits a class or a module: a class here is a function
54
+ * whose `prototype` is non-writable, which holds for `class` syntax and the
55
+ * built-in constructors and for no arrow, bound or `function` function — the
56
+ * test `rbInspect` applies before rendering a value through `rbModToS`.
57
+ * Setting a name an autoload holds deletes the autoload, as
58
+ * `const_tbl_update` does (vendor/ruby/v3.3.11/variable.c:3710-3724).
59
+ *
60
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
61
+ */
62
+ export function constSet(mod, id, value) {
63
+ if (!/^[\p{Lu}\p{Lt}](?:\w|\P{ASCII})*$/u.test(id)) {
64
+ throw new NameError(`wrong constant name ${id}`, id);
65
+ }
66
+ Object.defineProperty(mod, id, { value, writable: true, enumerable: true, configurable: true });
67
+ autoloadDelete(mod === TopLevel ? Object : mod, id);
68
+ if (value instanceof Module ||
69
+ isPlainHash(value) ||
70
+ (typeof value === "function" &&
71
+ Object.getOwnPropertyDescriptor(value, "prototype")?.writable === false)) {
72
+ const klass = mod;
73
+ const valPath = classpaths.get(value);
74
+ if (mod === Object || mod === TopLevel) {
75
+ if (valPath?.permanent !== true)
76
+ classpaths.set(value, { path: id, permanent: true });
77
+ return value;
78
+ }
79
+ const parentalPathPermanent = mod instanceof Module || (isPlainHash(mod) && classpaths.has(mod))
80
+ ? classpaths.get(mod)?.permanent === true
81
+ : Boolean(mod.name);
82
+ const parentalPath = parentalPathPermanent
83
+ ? mod instanceof Module
84
+ ? mod.name
85
+ : rbModName(klass)
86
+ : mod instanceof Module
87
+ ? mod.inspect()
88
+ : rbModToS(klass);
89
+ if (parentalPathPermanent && valPath?.permanent !== true) {
90
+ classpaths.set(value, mod instanceof Module || classpaths.has(mod)
91
+ ? { path: `${parentalPath}::${id}`, permanent: true }
92
+ : { path: `${parentalPath}::${id}`, permanent: true, under: mod, id });
93
+ }
94
+ else if (!parentalPathPermanent && valPath === undefined) {
95
+ classpaths.set(value, { path: `${parentalPath}::${id}`, permanent: false });
96
+ }
97
+ }
98
+ return value;
99
+ }
100
+ /**
101
+ * Mirrors: Ruby's Module#const_defined? — vendor/ruby/v3.3.11/object.c:2596
102
+ * `rb_mod_const_defined`, which raises `NameError` for a name that is not a
103
+ * constant name and otherwise answers `rb_const_defined`: the constant on the
104
+ * module or one of its ancestors, or on the module alone when `recur` is
105
+ * false. A `::` path is walked a segment at a time, each
106
+ * later segment read from the namespace before it alone, and the first also
107
+ * from the top-level table `TopLevel`.
108
+ *
109
+ * @noRailsEquivalent PERMANENT
110
+ */
111
+ export function constDefined(mod, name, recur = true) {
112
+ let c = mod;
113
+ for (const [i, part] of name.split("::").entries()) {
114
+ if (!/^[\p{Lu}\p{Lt}](?:\w|\P{ASCII})*$/u.test(part)) {
115
+ throw new NameError(`wrong constant name ${name}`, name);
116
+ }
117
+ if (c === null || (typeof c !== "object" && typeof c !== "function"))
118
+ return false;
119
+ if (i === 0 && recur ? part in c : Object.hasOwn(c, part)) {
120
+ c = c[part];
121
+ }
122
+ else if (i === 0 && (recur || mod === Object) && Object.hasOwn(TopLevel, part)) {
123
+ c = TopLevel[part];
124
+ }
125
+ else {
126
+ return false;
127
+ }
128
+ }
129
+ return true;
130
+ }
131
+ /**
132
+ * Ruby's `Module.new` — an anonymous module built at runtime and populated
133
+ * after the fact (`mod.module_eval { define_method … }`), then mixed into a
134
+ * class with `include`.
135
+ *
136
+ * Unlike a plain-object module, whose methods `include()` copies onto the
137
+ * class prototype once, a `Module` instance is *live*: `include()` splices a
138
+ * carrier object into the prototype chain directly below the including class's
139
+ * prototype, and every method the module defines afterwards is found by
140
+ * instances from then on. That is Ruby's actual include semantics — including
141
+ * that a method defined in the class body outranks the module's.
142
+ *
143
+ * The carrier is a separate object from the module because a JS object cannot
144
+ * be both: everything reachable from a link in an instance's prototype chain is
145
+ * an instance method, whereas Ruby's module object carries its own methods
146
+ * (`Module#inspect`, `#name`) outside the ancestry it contributes. So the
147
+ * module's methods are reached through the Ruby-named Module API below, which
148
+ * operates on the carrier.
149
+ *
150
+ * Mirrors: Ruby's Module.new — vendor/ruby/v3.3.11/object.c:1950 `rb_mod_initialize`.
151
+ *
152
+ * @noRailsEquivalent PERMANENT — a Ruby core class, not a Rails one.
153
+ */
154
+ export class Module {
155
+ /**
156
+ * Mirrors: Ruby's Module.new — vendor/ruby/v3.3.11/object.c:1950
157
+ * `rb_mod_initialize`, which hands a given block the new module
158
+ * (`rb_mod_module_exec(1, &module, module)`, object.c:1959).
159
+ *
160
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
161
+ */
162
+ constructor(block) {
163
+ if (block !== undefined)
164
+ block(this);
165
+ }
166
+ /**
167
+ * Mirrors: Ruby's Module#to_s — vendor/ruby/v3.3.11/object.c:1710
168
+ * `rb_mod_to_s`, the method `Module#inspect` is an alias of
169
+ * (vendor/ruby/v3.3.11/object.c:4438-4439).
170
+ *
171
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
172
+ */
173
+ toS() {
174
+ return this.name ?? rbAnyToS(this);
175
+ }
176
+ /**
177
+ * Mirrors: Ruby's Module#inspect — vendor/ruby/v3.3.11/object.c:1710
178
+ * `rb_mod_to_s`, which renders `rb_class_name`: the classpath, or the
179
+ * `#<Klass:0x…>` path `make_temporary_path` (vendor/ruby/v3.3.11/variable.c:320)
180
+ * gives an anonymous one.
181
+ *
182
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
183
+ */
184
+ inspect() {
185
+ return modToS.call(this);
186
+ }
187
+ /**
188
+ * Mirrors: Ruby's Module#name — vendor/ruby/v3.3.11/variable.c:122
189
+ * `rb_mod_name`: the classpath `const_set` gave the module, or `nil` while
190
+ * it is anonymous.
191
+ *
192
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
193
+ */
194
+ get name() {
195
+ return rbClassPath(this) ?? null;
196
+ }
197
+ /**
198
+ * Mirrors: Ruby's Module#module_eval — vendor/ruby/v3.3.11/vm_eval.c:2128
199
+ * `rb_mod_module_eval` — yields the module's method table, with the module
200
+ * as `this` (the block's `self`), so a block can call `this.include(...)`.
201
+ *
202
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
203
+ */
204
+ moduleEval(block) {
205
+ const carrier = carrierOf(this);
206
+ const before = Object.getOwnPropertyDescriptors(carrier);
207
+ const result = block.call(this, carrier);
208
+ for (const [key, entry] of Object.entries(Object.getOwnPropertyDescriptors(carrier))) {
209
+ if (entry.configurable && !("value" in entry) && (!entry.get || !entry.set)) {
210
+ defineAccessorHalf(carrier, key, {});
211
+ }
212
+ }
213
+ const installed = trackedKeys(carrier);
214
+ for (const key of installed) {
215
+ const after = Object.getOwnPropertyDescriptor(carrier, key);
216
+ if (after?.value !== before[key]?.value || after?.get !== before[key]?.get) {
217
+ installed.delete(key);
218
+ }
219
+ }
220
+ relinkIncluders(this);
221
+ return result;
222
+ }
223
+ /**
224
+ * Mirrors: Ruby's Module#include into a module — vendor/ruby/v3.3.11/class.c:1179
225
+ * `rb_include_module`, which splices `mod` BELOW this module, so a method
226
+ * this module defines itself outranks the included one. A module already
227
+ * included is skipped (`include_modules_at`, class.c:1281,1291,1296). A
228
+ * module defining `appendFeatures` gets that call instead, then `included`,
229
+ * as `rb_mod_include` sends both (vendor/ruby/v3.3.11/eval.c:1159-1160).
230
+ * `ensure_includable` (class.c:1168-1176) rejects a Ruby `Class`; a TS class
231
+ * passed here is a class module, the spelling {@link include} already takes
232
+ * for a Ruby module that carries accessors, so its prototype methods are
233
+ * the module's method table.
234
+ *
235
+ * A plain-object module's getter and setter are methods too (`def title` /
236
+ * `def title=`), so the pair is carried as an accessor, uncalled. An ES
237
+ * module namespace (`import * as Helper`) is the exception: its exports are
238
+ * functions a bundler may serve through getters, so each is read and
239
+ * installed as the method it names.
240
+ *
241
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
242
+ */
243
+ include(mod) {
244
+ rbClearMethodCache();
245
+ const appendFeatures = featureHook(mod, "appendFeatures");
246
+ if (appendFeatures) {
247
+ appendFeatures(this);
248
+ if (typeof mod[included] === "function") {
249
+ mod[included](this);
250
+ }
251
+ else {
252
+ featureHook(mod, "included")?.(this);
253
+ }
254
+ return this;
255
+ }
256
+ if (mod instanceof Module) {
257
+ Module.prototype.appendFeatures.call(mod, this);
258
+ if (typeof mod[included] === "function") {
259
+ mod[included](this);
260
+ }
261
+ else {
262
+ featureHook(mod, "included")?.(this);
263
+ }
264
+ return this;
265
+ }
266
+ appendPlainFeatures(this, mod);
267
+ if (typeof mod[included] === "function") {
268
+ mod[included](this);
269
+ }
270
+ return this;
271
+ }
272
+ /**
273
+ * Mirrors: Ruby's Module#include? — vendor/ruby/v3.3.11/class.c:1538
274
+ * `rb_mod_include_p`, which walks the module's ancestry, so a module
275
+ * included by an included module answers true.
276
+ *
277
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
278
+ */
279
+ isInclude(mod2) {
280
+ if (isModuleMethodTablePresent({ prototype: carrierOf(this) }, mod2))
281
+ return true;
282
+ return (nestedModules.get(this) ?? []).some((nested) => nested instanceof Module ? nested.isInclude(mod2) : rbModAncestors(nested).includes(mod2));
283
+ }
284
+ /**
285
+ * Mirrors: Ruby's Module#define_method — vendor/ruby/v3.3.11/proc.c:2325
286
+ * `rb_mod_define_method`.
287
+ *
288
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
289
+ */
290
+ defineMethod(name, body) {
291
+ trackedKeys(carrierOf(this)).delete(name);
292
+ Object.defineProperty(carrierOf(this), name, {
293
+ value: body,
294
+ writable: true,
295
+ configurable: true,
296
+ });
297
+ relinkIncluders(this);
298
+ }
299
+ /**
300
+ * Mirrors: Ruby's Module#instance_method — the named method, detached from
301
+ * this module. Ruby returns an `UnboundMethod`, which `define_method` binds
302
+ * into another module; the TS carrier of that is the property descriptor,
303
+ * which `Object.defineProperty` re-installs and which — unlike a bare
304
+ * function — also carries an accessor pair.
305
+ *
306
+ * vendor/ruby/v3.3.11/proc.c:2190 `rb_mod_instance_method`.
307
+ *
308
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
309
+ */
310
+ instanceMethod(name) {
311
+ for (const ancestor of this.ancestors()) {
312
+ if (ancestor instanceof Module) {
313
+ const entry = Object.getOwnPropertyDescriptor(carrierOf(ancestor), name);
314
+ if (entry !== undefined)
315
+ return entry;
316
+ continue;
317
+ }
318
+ if (name === "constructor" || /^[A-Z]/.test(name))
319
+ continue;
320
+ const members = (typeof ancestor === "function" ? ancestor.prototype : ancestor);
321
+ const descriptor = Object.getOwnPropertyDescriptor(members, name);
322
+ if (descriptor === undefined || (typeof ancestor !== "function" && !descriptor.enumerable)) {
323
+ continue;
324
+ }
325
+ const namespace = members[Symbol.toStringTag];
326
+ if (!("value" in descriptor) && namespace !== "Module") {
327
+ return { get: descriptor.get, set: descriptor.set, configurable: true };
328
+ }
329
+ if (typeof members[name] === "function") {
330
+ return { value: members[name], writable: true, configurable: true };
331
+ }
332
+ }
333
+ return undefined;
334
+ }
335
+ /**
336
+ * Mirrors: Ruby's Module#ancestors — vendor/ruby/v3.3.11/class.c:1570
337
+ * `rb_mod_ancestors`: the module, then the modules it includes, most
338
+ * recently included first, each followed by its own.
339
+ *
340
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
341
+ */
342
+ ancestors() {
343
+ const ary = [this];
344
+ const carrier = carrierOf(this);
345
+ const mods = Object.hasOwn(carrier, includedModulesKey)
346
+ ? [...carrier[includedModulesKey]]
347
+ : [];
348
+ for (const mod of mods.reverse()) {
349
+ for (const m of mod instanceof Module
350
+ ? mod.ancestors()
351
+ : isPlainHash(mod)
352
+ ? rbModAncestors(mod)
353
+ : [mod]) {
354
+ if (!ary.includes(m))
355
+ ary.push(m);
356
+ }
357
+ }
358
+ return ary;
359
+ }
360
+ /**
361
+ * Mirrors: Ruby's Module#instance_methods — vendor/ruby/v3.3.11/class.c:1889
362
+ * `rb_class_instance_methods`, whose `include_super` defaults to true: the
363
+ * methods of the module's ancestors follow its own, and a name a nearer
364
+ * module undefines stays hidden.
365
+ *
366
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
367
+ */
368
+ instanceMethods(includeSuper = true) {
369
+ const seen = new Set();
370
+ const ary = [];
371
+ for (const mod of includeSuper ? this.ancestors() : [this]) {
372
+ if (!(mod instanceof Module))
373
+ continue;
374
+ const carrier = carrierOf(mod);
375
+ for (const name of Object.getOwnPropertyNames(carrier)) {
376
+ if (seen.has(name))
377
+ continue;
378
+ seen.add(name);
379
+ if (!isUndefEntry(carrier, name))
380
+ ary.push(name);
381
+ }
382
+ }
383
+ return ary;
384
+ }
385
+ /**
386
+ * Mirrors: Ruby's Module#remove_method — vendor/ruby/v3.3.11/vm_method.c:1728
387
+ * `rb_mod_remove_method`.
388
+ *
389
+ * @noRailsEquivalent PERMANENT
390
+ */
391
+ removeMethod(...names) {
392
+ const carrier = carrierOf(this);
393
+ try {
394
+ for (const name of names) {
395
+ if (!Object.hasOwn(carrier, name)) {
396
+ throw new NameError(`method '${name}' not defined in #<Module>`, name);
397
+ }
398
+ delete carrier[name];
399
+ }
400
+ }
401
+ finally {
402
+ relinkIncluders(this);
403
+ }
404
+ return this;
405
+ }
406
+ /**
407
+ * Mirrors: Ruby's Module#undef_method — vendor/ruby/v3.3.11/vm_method.c:1973
408
+ * `rb_mod_undef_method`.
409
+ *
410
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
411
+ */
412
+ undefMethod(...names) {
413
+ const carrier = carrierOf(this);
414
+ try {
415
+ for (const name of names) {
416
+ const entry = this.instanceMethod(name);
417
+ if (entry === undefined || ("value" in entry && entry.value === undefined)) {
418
+ throw new NameError(`undefined method '${name}' for module '#<Module>'`, name);
419
+ }
420
+ trackedKeys(carrier).delete(name);
421
+ Object.defineProperty(carrier, name, {
422
+ value: undefined,
423
+ writable: true,
424
+ configurable: true,
425
+ });
426
+ }
427
+ }
428
+ finally {
429
+ relinkIncluders(this);
430
+ }
431
+ return this;
432
+ }
433
+ /**
434
+ * Mirrors: Ruby's Module#alias_method — vendor/ruby/v3.3.11/vm_method.c:2366
435
+ * `rb_mod_alias_method`.
436
+ *
437
+ * @noRailsEquivalent PERMANENT
438
+ */
439
+ aliasMethod(newName, oldName) {
440
+ const descriptor = this.instanceMethod(oldName);
441
+ if (!descriptor) {
442
+ throw new NameError(`undefined method '${oldName}' for module '#<Module>'`, oldName);
443
+ }
444
+ trackedKeys(carrierOf(this)).delete(newName);
445
+ Object.defineProperty(carrierOf(this), newName, descriptor);
446
+ relinkIncluders(this);
447
+ return newName;
448
+ }
449
+ /**
450
+ * Mirrors: Ruby's Module#append_features — vendor/ruby/v3.3.11/eval.c:1110
451
+ * `rb_mod_append_features`, the splice `include` runs before `included`.
452
+ * A `Module` this module included is spliced beneath it, as
453
+ * `include_modules_at` (vendor/ruby/v3.3.11/class.c:1253) walks the included
454
+ * module's own ancestry, skipping one already in `base`'s. A `Module` base is
455
+ * a module including this one: every class already including `base` gets it
456
+ * too, as `rb_include_module` walks `base`'s subclasses
457
+ * (vendor/ruby/v3.3.11/class.c:1189-1215).
458
+ *
459
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
460
+ */
461
+ appendFeatures(base) {
462
+ rbClearMethodCache();
463
+ if (base instanceof Module) {
464
+ const carrier = carrierOf(base);
465
+ if (isModuleMethodTablePresent({ prototype: carrier }, this))
466
+ return;
467
+ trackIncludedModule(carrier, this);
468
+ let nested = nestedModules.get(base);
469
+ if (!nested)
470
+ nestedModules.set(base, (nested = []));
471
+ nested.push(this);
472
+ for (const link of includerCarriers.get(base) ?? []) {
473
+ if (!isModuleMethodTablePresent({ prototype: link }, this)) {
474
+ Module.prototype.appendFeatures.call(this, { prototype: link });
475
+ }
476
+ }
477
+ return;
478
+ }
479
+ for (const mod of nestedModules.get(this) ?? []) {
480
+ if (isModuleMethodTablePresent(base, mod))
481
+ continue;
482
+ if (mod instanceof Module)
483
+ Module.prototype.appendFeatures.call(mod, base);
484
+ else
485
+ splicePlainModule(prependOrigins.get(base.prototype) ?? base.prototype, mod);
486
+ }
487
+ trackIncludedModule(base.prototype, this);
488
+ const proto = prependOrigins.get(base.prototype) ?? base.prototype;
489
+ const link = Object.create(Object.getPrototypeOf(proto));
490
+ Object.defineProperties(link, Object.getOwnPropertyDescriptors(carrierOf(this)));
491
+ let links = includerCarriers.get(this);
492
+ if (!links)
493
+ includerCarriers.set(this, (links = []));
494
+ links.push(link);
495
+ UNDEF_METHOD_TABLES.add(link);
496
+ Object.defineProperty(link, T_ICLASS, { value: this });
497
+ Object.setPrototypeOf(proto, link);
498
+ rbClearMethodCache();
499
+ }
500
+ /**
501
+ * Mirrors: Ruby's Module#prepend_features — vendor/ruby/v3.3.11/eval.c:1175
502
+ * `rb_mod_prepend_features`, the splice `prepend` runs before `prepended`.
503
+ * `rb_prepend_module` (vendor/ruby/v3.3.11/class.c:1430) moves the class's
504
+ * method table to an origin iclass (`ensure_origin`, class.c:1379) and
505
+ * splices the module between the class and that origin, so `superMethod`
506
+ * resumes at the class's own method. Here the origin holds the class's
507
+ * methods of the names the module defines; a later `include` is spliced
508
+ * beneath it, as `rb_include_module` splices at `RCLASS_ORIGIN`
509
+ * (class.c:1186). The origin is an iclass owned by the class, so
510
+ * `rbClassSuperclass` skips it and `methodOwner` answers the class for a
511
+ * method it holds.
512
+ *
513
+ * Two things MRI does have no JS counterpart. A method assigned to the
514
+ * class after the prepend lands on the class, above the module, where
515
+ * Ruby's `def` lands in the origin; and a moved method that calls
516
+ * `super.name()` resumes from the class, its home object, and so re-enters
517
+ * the module. A class whose own property of one of the module's names
518
+ * cannot be moved raises `TypeError`.
519
+ *
520
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
521
+ */
522
+ prependFeatures(base) {
523
+ rbClearMethodCache();
524
+ trackIncludedModule(base.prototype, this);
525
+ const proto = base.prototype;
526
+ const source = carrierOf(this);
527
+ let origin = prependOrigins.get(proto);
528
+ if (!origin) {
529
+ origin = iclassBeneath(proto, Object.getPrototypeOf(proto));
530
+ Object.defineProperty(origin, T_ICLASS, {
531
+ value: typeof proto === "function" ? proto : proto.constructor,
532
+ });
533
+ prependOrigins.set(proto, origin);
534
+ Object.setPrototypeOf(proto, origin);
535
+ }
536
+ const keys = new Set(Object.getOwnPropertyNames(source));
537
+ for (const mod of nestedModules.get(this) ?? []) {
538
+ if (!(mod instanceof Module)) {
539
+ for (const key of typeof mod === "function"
540
+ ? Object.getOwnPropertyNames(mod.prototype)
541
+ : Object.keys(mod)) {
542
+ if (this.instanceMethod(key) !== undefined)
543
+ keys.add(key);
544
+ }
545
+ }
546
+ }
547
+ for (const key of keys) {
548
+ const descriptor = Object.getOwnPropertyDescriptor(proto, key);
549
+ if (descriptor === undefined)
550
+ continue;
551
+ if (!descriptor.configurable) {
552
+ throw new TypeError(`prepend: cannot move ${key}, a non-configurable own property`);
553
+ }
554
+ Object.defineProperty(origin, key, descriptor);
555
+ delete proto[key];
556
+ }
557
+ const link = iclassBeneath(proto, Object.getPrototypeOf(proto));
558
+ Object.defineProperties(link, Object.getOwnPropertyDescriptors(source));
559
+ let links = includerCarriers.get(this);
560
+ if (!links)
561
+ includerCarriers.set(this, (links = []));
562
+ links.push(link);
563
+ UNDEF_METHOD_TABLES.add(link);
564
+ Object.defineProperty(link, T_ICLASS, { value: this });
565
+ Object.setPrototypeOf(proto, link);
566
+ for (const mod of nestedModules.get(this) ?? []) {
567
+ if (!(mod instanceof Module))
568
+ splicePlainModule(link, mod);
569
+ }
570
+ rbClearMethodCache();
571
+ }
572
+ /**
573
+ * Mirrors: Ruby's Module#extend_object — vendor/ruby/v3.3.11/eval.c:1746
574
+ * `rb_mod_extend_object`, which `rb_extend_object` (:1713) runs as
575
+ * `rb_include_module(rb_singleton_class(obj), module)`: the module's link is
576
+ * spliced between `obj` and its class, so a later `extend` sits above it and
577
+ * `superMethod` resumes the lookup at the next link. A module already in
578
+ * `obj`'s ancestry is skipped, as `include_modules_at` skips one
579
+ * (vendor/ruby/v3.3.11/class.c:1281,1291,1296). A frozen object's singleton
580
+ * class is frozen, so `rb_class_modify_check` (vendor/ruby/v3.3.11/eval.c:429)
581
+ * raises `FrozenError` first.
582
+ *
583
+ * One link is made per extended object, so singleton links are held through
584
+ * `WeakRef`s that `relinkIncluders` still walks, keeping a later
585
+ * `defineMethod` visible on an already-extended object as Ruby's shared
586
+ * method table does, without retaining the object.
587
+ *
588
+ * A class's constructor reaches its superclass through the same prototype
589
+ * link (`super()` reads `Object.getPrototypeOf(klass)`), so the link spliced
590
+ * above a class is itself a subclass of the class's parent.
591
+ *
592
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
593
+ */
594
+ extendObject(obj) {
595
+ if (Object.isFrozen(obj)) {
596
+ const desc = obj instanceof Module
597
+ ? `Module: ${obj.inspect()}`
598
+ : typeof obj === "function"
599
+ ? `Class: ${rbModToS(obj)}`
600
+ : `object: ${rbInspect(obj)}`;
601
+ throw new FrozenError(`can't modify frozen ${desc}`, { receiver: obj });
602
+ }
603
+ for (let proto = Object.getPrototypeOf(obj); proto;) {
604
+ if (isLinkOf(this, proto))
605
+ return;
606
+ proto = Object.getPrototypeOf(proto);
607
+ }
608
+ for (const mod of nestedModules.get(this) ?? []) {
609
+ if (mod instanceof Module)
610
+ Module.prototype.extendObject.call(mod, obj);
611
+ }
612
+ const holder = typeof obj === "function" ? obj : rbObjSingletonClass(obj).prototype;
613
+ trackIncludedModule(holder, this);
614
+ const parent = Object.getPrototypeOf(holder);
615
+ const link = typeof obj === "function" && typeof parent === "function" && parent !== Function.prototype
616
+ ? class extends parent {
617
+ }
618
+ : Object.create(parent);
619
+ Object.defineProperties(link, Object.getOwnPropertyDescriptors(carrierOf(this)));
620
+ let links = singletonCarriers.get(this);
621
+ if (!links)
622
+ singletonCarriers.set(this, (links = { members: new WeakSet(), refs: new Set() }));
623
+ const ref = new WeakRef(link);
624
+ links.members.add(link);
625
+ UNDEF_METHOD_TABLES.add(link);
626
+ links.refs.add(ref);
627
+ singletonReaper.register(link, { mod: this, ref });
628
+ Object.defineProperty(link, T_ICLASS, { value: this });
629
+ Object.setPrototypeOf(holder, link);
630
+ for (const mod of nestedModules.get(this) ?? []) {
631
+ if (!(mod instanceof Module))
632
+ splicePlainModule(link, mod);
633
+ }
634
+ rbClearMethodCache();
635
+ }
636
+ /**
637
+ * Mirrors: Ruby's `super` from one of this module's methods —
638
+ * vendor/ruby/v3.3.11/vm_insnhelper.c:4648 `vm_search_super_method`, the lookup
639
+ * `Method#super_method` exposes (vendor/ruby/v3.3.11/proc.c:3391): resume the method
640
+ * search at `RCLASS_SUPER` of the iclass this module contributed to
641
+ * `receiver`'s ancestry. Answers the next method bound to `receiver`, or
642
+ * `undefined` where Ruby's `super_method` answers nil.
643
+ *
644
+ * A JS function's `super` is fixed to its home object, which for a carrier
645
+ * method is the module's own table, not the includer's link, so the link is
646
+ * found on the receiver's prototype chain instead.
647
+ *
648
+ * Every ancestry ends in `Object`, which includes `Kernel`, so a `super` that
649
+ * no link beneath the caller answers reaches `Kernel`'s method. No JS object
650
+ * stands at that root, so the search ends in the `Kernel` module's table.
651
+ *
652
+ * A reader and writer generated as one accessor pair are two Ruby methods,
653
+ * `name` and `name=`, so `name` answers the next getter and `name=` the next
654
+ * setter, each looked up independently the way Ruby looks each method up.
655
+ *
656
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
657
+ */
658
+ superMethod(receiver, name) {
659
+ for (let proto = Object.getPrototypeOf(receiver); proto;) {
660
+ if (isLinkOf(this, proto)) {
661
+ const writer = name.endsWith("=");
662
+ const key = writer ? name.slice(0, -1) : name;
663
+ const nested = nestedModules.get(this) ?? [];
664
+ let start = Object.getPrototypeOf(proto);
665
+ while (start &&
666
+ !Object.hasOwn(carrierOf(this), key) &&
667
+ nested.includes(start[T_ICLASS])) {
668
+ start = Object.getPrototypeOf(start);
669
+ }
670
+ for (let next = start; next;) {
671
+ const descriptor = Object.getOwnPropertyDescriptor(next, key);
672
+ next = Object.getPrototypeOf(next);
673
+ if (descriptor === undefined)
674
+ continue;
675
+ if (!("value" in descriptor)) {
676
+ const half = writer ? descriptor.set : descriptor.get;
677
+ if (half === undefined || isAbsentHalf(half))
678
+ continue;
679
+ return half.bind(receiver);
680
+ }
681
+ return !writer && typeof descriptor.value === "function"
682
+ ? descriptor.value.bind(receiver)
683
+ : undefined;
684
+ }
685
+ const root = writer || !Object.hasOwn(Kernel, key) ? undefined : Reflect.get(Kernel, key);
686
+ return typeof root === "function"
687
+ ? root.bind(receiver)
688
+ : undefined;
689
+ }
690
+ proto = Object.getPrototypeOf(proto);
691
+ }
692
+ return undefined;
693
+ }
694
+ /**
695
+ * Mirrors: Ruby's Module#attr_reader — vendor/ruby/v3.3.11/object.c:2279
696
+ * `rb_mod_attr_reader`.
697
+ *
698
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
699
+ */
700
+ attrReader(...argv) {
701
+ this.moduleEval((mod) => rbModAttrReader({ prototype: mod }, ...argv));
702
+ }
703
+ /**
704
+ * Mirrors: Ruby's Module#attr_writer — vendor/ruby/v3.3.11/object.c:2335
705
+ * `rb_mod_attr_writer`.
706
+ *
707
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
708
+ */
709
+ attrWriter(...argv) {
710
+ this.moduleEval((mod) => rbModAttrWriter({ prototype: mod }, ...argv));
711
+ }
712
+ /**
713
+ * Mirrors: Ruby's Module#method_defined? — vendor/ruby/v3.3.11/vm_method.c:2055
714
+ * `rb_mod_method_defined`.
715
+ *
716
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
717
+ */
718
+ isMethodDefined(name) {
719
+ const carrier = carrierOf(this);
720
+ return (Object.hasOwn(carrier, name) &&
721
+ !isUndefEntry(carrier, name) &&
722
+ !isAbsentHalf(Object.getOwnPropertyDescriptor(carrier, name).get));
723
+ }
724
+ /**
725
+ * Mirrors: Ruby's Module#dup — vendor/ruby/v3.3.11/object.c:591 `rb_obj_dup`,
726
+ * whose `initialize_copy` is vendor/ruby/v3.3.11/class.c:524 `rb_mod_init_copy`:
727
+ * the copy gets its own method table and a clone of the singleton class
728
+ * (`rb_singleton_class_clone`, :545-548), and shares the modules it includes.
729
+ * Nothing that already includes the original includes the copy.
730
+ *
731
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
732
+ */
733
+ dup() {
734
+ const copy = rbObjClone(this);
735
+ const table = Object.getOwnPropertyDescriptors(carrierOf(this));
736
+ for (const registry of [includedKeys, includedModulesKey]) {
737
+ const set = table[registry];
738
+ if (set)
739
+ table[registry] = { ...set, value: new Set(set.value) };
740
+ }
741
+ carriers.set(copy, Object.create(null, table));
742
+ const nested = nestedModules.get(this);
743
+ if (nested)
744
+ nestedModules.set(copy, [...nested]);
745
+ return copy;
746
+ }
747
+ }
748
+ function appendPlainFeatures(base, mod) {
749
+ if (!isModuleMethodTablePresent({ prototype: carrierOf(base) }, mod))
750
+ recordPlainModule(base, mod);
751
+ }
752
+ function recordPlainModule(base, mod) {
753
+ const carrier = carrierOf(base);
754
+ const links = (includerCarriers.get(base) ?? []).filter((link) => !isModuleMethodTablePresent({ prototype: Object.getPrototypeOf(link) }, mod));
755
+ trackIncludedModule(carrier, mod);
756
+ let nested = nestedModules.get(base);
757
+ if (!nested)
758
+ nestedModules.set(base, (nested = []));
759
+ nested.push(mod);
760
+ for (const link of links)
761
+ splicePlainModule(link, mod);
762
+ }
763
+ function splicePlainModule(proto, mod) {
764
+ function iclass() { }
765
+ iclass.prototype = iclassBeneath(proto, Object.getPrototypeOf(proto));
766
+ Object.defineProperty(iclass.prototype, T_ICLASS, { value: mod });
767
+ rbModAppendFeatures(iclass, mod);
768
+ Object.setPrototypeOf(proto, iclass.prototype);
769
+ }
770
+ const modToS = Module.prototype.toS;
771
+ const carriers = new WeakMap();
772
+ const nestedModules = new WeakMap();
773
+ function carrierOf(mod) {
774
+ let carrier = carriers.get(mod);
775
+ if (!carrier) {
776
+ carrier = Object.create(null);
777
+ carriers.set(mod, carrier);
778
+ }
779
+ return carrier;
780
+ }
781
+ function isUndefEntry(carrier, name) {
782
+ const descriptor = Object.getOwnPropertyDescriptor(carrier, name);
783
+ return descriptor !== undefined && "value" in descriptor && descriptor.value === undefined;
784
+ }
785
+ const includerCarriers = new WeakMap();
786
+ const singletonCarriers = new WeakMap();
787
+ const singletonReaper = new FinalizationRegistry(({ mod, ref }) => singletonCarriers.get(mod)?.refs.delete(ref));
788
+ const prependOrigins = new WeakMap();
789
+ function iclassBeneath(obj, parent) {
790
+ return typeof obj === "function" && typeof parent === "function" && parent !== Function.prototype
791
+ ? class extends parent {
792
+ }
793
+ : Object.create(parent);
794
+ }
795
+ function isLinkOf(mod, proto) {
796
+ return ((includerCarriers.get(mod)?.includes(proto) ?? false) ||
797
+ (singletonCarriers.get(mod)?.members.has(proto) ?? false));
798
+ }
799
+ function linksOf(mod) {
800
+ const singletons = [];
801
+ for (const ref of singletonCarriers.get(mod)?.refs ?? []) {
802
+ const link = ref.deref();
803
+ if (link)
804
+ singletons.push(link);
805
+ }
806
+ return [...(includerCarriers.get(mod) ?? []), ...singletons];
807
+ }
808
+ function relinkIncluders(mod) {
809
+ rbClearMethodCache();
810
+ const table = carrierOf(mod);
811
+ for (const link of linksOf(mod)) {
812
+ for (const name of Object.getOwnPropertyNames(link)) {
813
+ if (!Object.hasOwn(table, name) && Object.getOwnPropertyDescriptor(link, name).configurable)
814
+ delete link[name];
815
+ }
816
+ Object.defineProperties(link, Object.getOwnPropertyDescriptors(table));
817
+ }
818
+ }
819
+ export { methodCacheSerial, rbClearMethodCache };
820
+ /**
821
+ * Symbol key for Ruby's Module#included callback, which `rb_mod_include` fires
822
+ * on the module once `append_features` has spliced it into the ancestry
823
+ * (vendor/ruby/v3.3.11/eval.c:1160). Using a symbol avoids collisions with real method
824
+ * names.
825
+ *
826
+ * @noRailsEquivalent PERMANENT — Ruby names the hook with an ordinary method
827
+ * definition on the module; TypeScript has no such lifecycle hook, so the key
828
+ * carries the name instead.
829
+ */
830
+ export const included = Symbol.for("@blazetrails/ruby-compat:included");
831
+ /**
832
+ * Symbol key for Ruby's Module#extended callback, which `rb_obj_extend` fires
833
+ * on the module after `extend_object` has copied its methods onto the object
834
+ * (vendor/ruby/v3.3.11/eval.c:1795).
835
+ *
836
+ * @noRailsEquivalent PERMANENT — the TypeScript spelling of a Ruby lifecycle
837
+ * hook, which the language has no equivalent of.
838
+ */
839
+ export const extended = Symbol.for("@blazetrails/ruby-compat:extended");
840
+ /**
841
+ * Symbol key for Ruby's Class#inherited callback, which `rb_class_inherited`
842
+ * calls on the superclass with the new subclass
843
+ * (vendor/ruby/v3.3.11/class.c:963). JS runs nothing when a class is defined,
844
+ * so the call is made where trails first learns of the subclass:
845
+ * `DescendantsTracker.registerSubclass` adding a new edge (CLAUDE.md
846
+ * § "`inherited` is deferred to own-property memo guards").
847
+ *
848
+ * @noRailsEquivalent PERMANENT
849
+ */
850
+ export const inherited = Symbol.for("@blazetrails/ruby-compat:inherited");
851
+ /**
852
+ * Symbol key for Ruby's Module#prepended callback, which `rb_mod_prepend`
853
+ * fires on the module once `prepend_features` has spliced it into the
854
+ * ancestry, on every call (vendor/ruby/v3.3.11/eval.c:1215).
855
+ *
856
+ * @noRailsEquivalent PERMANENT — the TypeScript spelling of a Ruby lifecycle
857
+ * hook, which the language has no equivalent of.
858
+ */
859
+ export const prepended = Symbol.for("@blazetrails/ruby-compat:prepended");
860
+ const includedKeys = Symbol.for("@blazetrails/ruby-compat:includedKeys");
861
+ const extendedKeys = Symbol.for("@blazetrails/ruby-compat:extendedKeys");
862
+ const includedModulesKey = Symbol.for("@blazetrails/ruby-compat:includedModules");
863
+ const moduleIncludesKey = Symbol.for("@blazetrails/ruby-compat:moduleIncludes");
864
+ const extendedOwners = new WeakMap();
865
+ const delegateClass = Symbol.for("@blazetrails/ruby-compat:delegateClass");
866
+ const STATIC_CLASS_KEYS = new Set(["prototype", "length", "name"]);
867
+ function trackedKeys(proto, registry = includedKeys) {
868
+ let set = proto[registry];
869
+ if (!Object.hasOwn(proto, registry)) {
870
+ set = new Set();
871
+ Object.defineProperty(proto, registry, {
872
+ value: set,
873
+ writable: true,
874
+ configurable: true,
875
+ enumerable: false,
876
+ });
877
+ }
878
+ return set;
879
+ }
880
+ function trackIncludedModule(proto, mod, registry = includedModulesKey) {
881
+ let set = proto[registry];
882
+ if (!Object.hasOwn(proto, registry)) {
883
+ set = new Set();
884
+ Object.defineProperty(proto, registry, {
885
+ value: set,
886
+ writable: true,
887
+ configurable: true,
888
+ enumerable: false,
889
+ });
890
+ }
891
+ if (!set.has(mod))
892
+ rbClearMethodCache();
893
+ set.add(mod);
894
+ }
895
+ function isModuleMethodTablePresent(klass, mod) {
896
+ for (let proto = klass.prototype; proto; proto = Object.getPrototypeOf(proto)) {
897
+ if (Object.hasOwn(proto, includedModulesKey) &&
898
+ proto[includedModulesKey].has(mod)) {
899
+ return true;
900
+ }
901
+ if (Object.hasOwn(proto, delegateClass))
902
+ break;
903
+ }
904
+ return false;
905
+ }
906
+ /**
907
+ * Ruby's `Module#<` — is `mod` in `klass`'s ancestry?
908
+ *
909
+ * `ActiveRecord::AttributeMethods::Dirty`'s `included do` block asks exactly
910
+ * this (`activerecord/lib/active_record/attribute_methods/dirty.rb:44-47`,
911
+ * `if self < ::ActiveRecord::Timestamp`), and there is no other way to ask it
912
+ * here: JavaScript keeps no ancestry record of a mixin, since `include()`
913
+ * copies a module's members onto the prototype rather than splicing a link for
914
+ * it. The registry `include()` keeps is that record.
915
+ *
916
+ * Mirrors: Ruby's Module#include? — vendor/ruby/v3.3.11/class.c:1538
917
+ * `rb_mod_include_p`.
918
+ *
919
+ * @noRailsEquivalent PERMANENT — Ruby spells this `<`, an operator TypeScript
920
+ * cannot define; the predicate carries the same question at a callable name.
921
+ */
922
+ export function isModuleIncluded(klass, mod) {
923
+ if (isPlainHash(klass) && !Object.hasOwn(klass, "prototype")) {
924
+ return klass !== mod && rbModAncestors(klass).includes(mod);
925
+ }
926
+ return isModuleMethodTablePresent(klass, mod);
927
+ }
928
+ /**
929
+ * Ruby's `Module#included_modules`: every module in `mod`'s ancestry, most
930
+ * recently mixed in first. A class's singleton ancestry is its constructor's
931
+ * static chain, so `includedModules({ prototype: klass })` answers
932
+ * `klass.singleton_class.included_modules`.
933
+ *
934
+ * Mirrors: Ruby's Module#included_modules — vendor/ruby/v3.3.11/class.c:1508
935
+ * `rb_mod_included_modules`.
936
+ *
937
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
938
+ */
939
+ export function includedModules(mod) {
940
+ const result = [];
941
+ for (let proto = mod.prototype; proto; proto = Object.getPrototypeOf(proto)) {
942
+ if (!Object.hasOwn(proto, includedModulesKey))
943
+ continue;
944
+ const mods = [...proto[includedModulesKey]];
945
+ for (const m of mods.reverse())
946
+ if (!result.includes(m))
947
+ result.push(m);
948
+ }
949
+ return result;
950
+ }
951
+ /**
952
+ * Ruby's `Module#ancestors`: the class, the modules mixed into it most
953
+ * recently first, and then the same for each superclass up to `Object`.
954
+ * `rb_mod_ancestors` reads the iclass of an included module off the
955
+ * superclass chain; the registry `include()` keeps on each prototype is that
956
+ * record here.
957
+ *
958
+ * `Object.prototype` is the seat of `Object`, whose own ancestry
959
+ * (`Kernel`, `BasicObject`) no JS prototype carries.
960
+ *
961
+ * Mirrors: Ruby's Module#ancestors — vendor/ruby/v3.3.11/class.c:1570
962
+ * `rb_mod_ancestors`.
963
+ *
964
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
965
+ */
966
+ export function rbModAncestors(mod) {
967
+ if (isPlainHash(mod) && !Object.hasOwn(mod, "prototype")) {
968
+ const ary = [mod];
969
+ const mods = Object.hasOwn(mod, moduleIncludesKey)
970
+ ? [...mod[moduleIncludesKey]]
971
+ : [];
972
+ for (const m of mods.reverse()) {
973
+ const chain = m instanceof Module ? m.ancestors() : isPlainHash(m) ? rbModAncestors(m) : [m];
974
+ for (const a of chain)
975
+ if (!ary.includes(a))
976
+ ary.push(a);
977
+ }
978
+ return ary;
979
+ }
980
+ const ary = [];
981
+ for (let p = mod.prototype; p; p = Object.getPrototypeOf(p)) {
982
+ if (Object.hasOwn(p, "constructor")) {
983
+ const klass = p.constructor;
984
+ if (!ary.includes(reopened(klass)))
985
+ ary.push(klass);
986
+ }
987
+ if (Object.hasOwn(p, includedModulesKey)) {
988
+ const mods = [...p[includedModulesKey]];
989
+ for (const m of mods.reverse())
990
+ if (!ary.includes(m))
991
+ ary.push(m);
992
+ }
993
+ if (p === Uint8Array.prototype) {
994
+ for (const m of rbModAncestors(rbCString))
995
+ if (!ary.includes(m))
996
+ ary.push(m);
997
+ return ary;
998
+ }
999
+ if (p === Object.prototype)
1000
+ ary.push(Kernel, rbCBasicObject);
1001
+ }
1002
+ return ary;
1003
+ }
1004
+ /**
1005
+ * `rb_obj_is_kind_of` (`vendor/ruby/v3.3.11/object.c:889`), `Object#kind_of?`
1006
+ * and `Module#===`: whether `c` is in the ancestry of `obj`'s class. A plain
1007
+ * object is a module once seated or built by `defineModule`, as `include()`
1008
+ * takes one, and JS's own `Set` is
1009
+ * the seat of the `Set` that reopens it (`class Set extends JsSet`). A Symbol
1010
+ * is a colon-spelled string, whose class `rbObjClass` answers as `String`, so
1011
+ * `Symbol === obj` and `String === obj` are answered by the spelling.
1012
+ *
1013
+ * @noRailsEquivalent PERMANENT
1014
+ */
1015
+ export function rbObjIsKindOf(obj, c) {
1016
+ if (c === rbCSymbol)
1017
+ return isSymbol(obj);
1018
+ if (c === rbCString && isSymbol(obj))
1019
+ return false;
1020
+ if ((typeof c === "function" || (typeof c === "object" && c !== null)) &&
1021
+ singletonSearchAncestor(obj, c)) {
1022
+ return true;
1023
+ }
1024
+ const cl = rbObjClass(obj);
1025
+ if (cl === c)
1026
+ return true;
1027
+ if (typeof c === "function" || (typeof c === "object" && c !== null)) {
1028
+ return classSearchAncestor(cl, c);
1029
+ }
1030
+ else {
1031
+ throw new TypeError("class or module required");
1032
+ }
1033
+ }
1034
+ /**
1035
+ * `class_search_ancestor` (`vendor/ruby/v3.3.11/object.c:935`) over the
1036
+ * singleton class `CLASS_OF(obj)` starts at: the modules `obj` was `extend`ed
1037
+ * with, and for a class those of its superclasses too.
1038
+ */
1039
+ function singletonSearchAncestor(obj, c) {
1040
+ if (typeof obj !== "function" && (typeof obj !== "object" || obj === null))
1041
+ return false;
1042
+ for (let p = obj; p; p = typeof p === "function" ? Object.getPrototypeOf(p) : null) {
1043
+ if (!Object.hasOwn(p, extendedKeys) || !Object.hasOwn(p, includedModulesKey))
1044
+ continue;
1045
+ const mods = p[includedModulesKey];
1046
+ if (mods.has(c))
1047
+ return true;
1048
+ if (typeof c !== "object")
1049
+ continue;
1050
+ for (const m of mods) {
1051
+ if (typeof m === "object" && Object.prototype.isPrototypeOf.call(c, m))
1052
+ return true;
1053
+ }
1054
+ }
1055
+ return false;
1056
+ }
1057
+ /**
1058
+ * `rb_class_inherited_p` (`vendor/ruby/v3.3.11/object.c:1778`), `Module#<=`:
1059
+ * true when `mod` is `arg` or has it in its ancestry, false when `arg` has
1060
+ * `mod` in its own, and nil when the two are unrelated. The class-to-class
1061
+ * arm reads `RCLASS_SUPERCLASS_DEPTH`, a cache no JS class carries, so both
1062
+ * arms search the ancestry.
1063
+ *
1064
+ * @noRailsEquivalent PERMANENT
1065
+ */
1066
+ export function rbClassInheritedP(mod, arg) {
1067
+ if (mod === arg)
1068
+ return true;
1069
+ if (typeof arg !== "function" && (typeof arg !== "object" || arg === null)) {
1070
+ throw new TypeError("compared with non class/module");
1071
+ }
1072
+ if (classSearchAncestor(mod, arg)) {
1073
+ return true;
1074
+ }
1075
+ if (classSearchAncestor(arg, mod)) {
1076
+ return false;
1077
+ }
1078
+ return null;
1079
+ }
1080
+ /**
1081
+ * `rb_mod_ge` (`vendor/ruby/v3.3.11/object.c:1862`), `Module#>=`.
1082
+ *
1083
+ * @noRailsEquivalent PERMANENT
1084
+ */
1085
+ export function rbModGe(mod, arg) {
1086
+ if (typeof arg !== "function" && (typeof arg !== "object" || arg === null)) {
1087
+ throw new TypeError("compared with non class/module");
1088
+ }
1089
+ return rbClassInheritedP(arg, mod);
1090
+ }
1091
+ /**
1092
+ * `rb_mod_gt` (`vendor/ruby/v3.3.11/object.c:1885`), `Module#>`.
1093
+ *
1094
+ * @noRailsEquivalent PERMANENT
1095
+ */
1096
+ export function rbModGt(mod, arg) {
1097
+ if (mod === arg)
1098
+ return false;
1099
+ return rbModGe(mod, arg);
1100
+ }
1101
+ /** `class_search_ancestor` (`vendor/ruby/v3.3.11/object.c:935`). */
1102
+ function classSearchAncestor(cl, c) {
1103
+ for (let p = cl.prototype; p; p = Object.getPrototypeOf(p)) {
1104
+ if (Object.hasOwn(p, "constructor")) {
1105
+ const klass = p.constructor;
1106
+ if (klass === c || klass === reopened(c))
1107
+ return true;
1108
+ }
1109
+ if (Object.hasOwn(p, includedModulesKey)) {
1110
+ if (p[includedModulesKey].has(c))
1111
+ return true;
1112
+ }
1113
+ if (p === Uint8Array.prototype)
1114
+ return c === rbCString || classSearchAncestor(rbCString, c);
1115
+ if (p === String.prototype && (c === rbCString || classSearchAncestor(rbCString, c))) {
1116
+ return true;
1117
+ }
1118
+ if (p === globalThis.Set.prototype &&
1119
+ constDefined(Object, "Set") &&
1120
+ c === constGet(Object, "Set"))
1121
+ return true;
1122
+ if (p === Object.prototype && (c === Kernel || c === rbCBasicObject))
1123
+ return true;
1124
+ }
1125
+ return false;
1126
+ }
1127
+ /**
1128
+ * `rb_mod_instance_method` (`vendor/ruby/v3.3.11/proc.c:2190`), `Module#instance_method`,
1129
+ * answering the `owner` (`method_owner`, `vendor/ruby/v3.3.11/proc.c:1988`): the
1130
+ * {@link rbModAncestors} entry that defines `mid`. That is the `Module` an
1131
+ * iclass link stands for, the module `include()` copied the entry from, most
1132
+ * recently included first, or the class the prototype belongs to.
1133
+ *
1134
+ * An `Object.prototype` member raises `NameError`: no Ruby class defines it,
1135
+ * the line {@link rbModMethodDefined} draws for `Module#method_defined?`.
1136
+ *
1137
+ * @noRailsEquivalent PERMANENT
1138
+ */
1139
+ export function rbModInstanceMethod(mod, mid) {
1140
+ const method = mnewUnbound(mod.prototype, mid);
1141
+ if (method !== null)
1142
+ return method;
1143
+ throw new NameError(`undefined method '${mid}' for class '${rbModToS(mod)}'`, mid);
1144
+ }
1145
+ function mnewUnbound(start, mid) {
1146
+ const entry = methodEntry(start, mid);
1147
+ if (entry === null)
1148
+ return null;
1149
+ return {
1150
+ owner: entryOwner(entry, mid),
1151
+ superMethod: () => mnewUnbound(Object.getPrototypeOf(entry), mid),
1152
+ bindCall: (recv, ...args) => {
1153
+ const desc = Object.getOwnPropertyDescriptor(entry, mid);
1154
+ if (typeof desc.value === "function") {
1155
+ return desc.value.apply(recv, args);
1156
+ }
1157
+ return desc.get ? desc.get.call(recv) : desc.value;
1158
+ },
1159
+ };
1160
+ }
1161
+ function methodEntry(start, mid) {
1162
+ for (let link = start; link && link !== Object.prototype; link = Object.getPrototypeOf(link)) {
1163
+ if (Object.hasOwn(link, mid))
1164
+ return link;
1165
+ }
1166
+ return null;
1167
+ }
1168
+ /**
1169
+ * `method_owner` (`vendor/ruby/v3.3.11/proc.c:1988`) for the entry `mid` names from
1170
+ * `start`, or nil when there is none. An entry `extend()` copied onto an
1171
+ * object is owned by the module it came from, and a class's own static by the
1172
+ * class, which stands for its singleton class.
1173
+ *
1174
+ * @noRailsEquivalent PERMANENT
1175
+ */
1176
+ export function methodOwner(start, mid) {
1177
+ const entry = methodEntry(start, mid);
1178
+ return entry === null ? null : entryOwner(entry, mid);
1179
+ }
1180
+ function entryOwner(link, mid) {
1181
+ const table = link;
1182
+ if (Object.hasOwn(link, T_ICLASS))
1183
+ return table[T_ICLASS];
1184
+ if (Object.hasOwn(link, includedKeys) && table[includedKeys].has(mid)) {
1185
+ const mods = [...table[includedModulesKey]].reverse();
1186
+ const owner = mods.find((m) => {
1187
+ if (m instanceof Module)
1188
+ return false;
1189
+ if (typeof m === "function")
1190
+ return Object.hasOwn(m.prototype, mid);
1191
+ return methodEntry(m, mid) !== null;
1192
+ });
1193
+ if (owner !== undefined)
1194
+ return owner;
1195
+ }
1196
+ if (Object.hasOwn(link, extendedKeys) && table[extendedKeys].has(mid)) {
1197
+ const defined = extendedOwners.get(link)?.get(mid);
1198
+ if (defined !== undefined)
1199
+ return defined;
1200
+ for (const m of [...table[includedModulesKey]].reverse()) {
1201
+ const owner = m instanceof Module ? null : methodEntry(m, mid);
1202
+ if (owner !== null)
1203
+ return owner;
1204
+ }
1205
+ }
1206
+ if (typeof link === "function" && link !== Function.prototype)
1207
+ return link;
1208
+ return link.constructor;
1209
+ }
1210
+ /**
1211
+ * Symbol key for the per-section visibility record `defineModule` stamps onto
1212
+ * the flat module object it returns. Symbol-keyed so it never collides with a
1213
+ * real method name, and so `Object.keys()` consumers see the module unchanged.
1214
+ *
1215
+ * The sections it records are the ones Ruby reads back through
1216
+ * `Module#private_instance_methods` — vendor/ruby/v3.3.11/class.c:1927
1217
+ * `rb_class_private_instance_methods`.
1218
+ *
1219
+ * @noRailsEquivalent PERMANENT — Ruby carries visibility on the method entry
1220
+ * itself; a TS object literal has nowhere to put it but a side table.
1221
+ */
1222
+ export const moduleVisibility = Symbol.for("@blazetrails/ruby-compat:moduleVisibility");
1223
+ /**
1224
+ * Compose a module from its visibility sections, the way a Ruby module body
1225
+ * separates them with statement-position `private` / `protected` keywords.
1226
+ *
1227
+ * Returns the flat composition in section order — public, then protected, then
1228
+ * private — so `include()` and `Included<typeof ...>` consumers see exactly the
1229
+ * object a hand-written spread produced. The section membership is additionally
1230
+ * stamped under `moduleVisibility` for `publicInstanceMethods` to read.
1231
+ *
1232
+ * The sections must be pairwise disjoint. A name in two sections is silently
1233
+ * won by the last spread, which aliases like `buildHavingClause: buildWhereClause`
1234
+ * (query_methods.rb:1654) make plausible, so it is asserted rather than trusted.
1235
+ *
1236
+ * Mirrors: Ruby's Module.new body — vendor/ruby/v3.3.11/object.c:1950
1237
+ * `rb_mod_initialize`.
1238
+ *
1239
+ * @noRailsEquivalent PERMANENT — Ruby declares member visibility with
1240
+ * statement-position `private` / `protected` inside the module body; a TS
1241
+ * object literal has no statement position, so the sections must be named
1242
+ * values and composed explicitly.
1243
+ */
1244
+ export function defineModule(publicSection, protectedSection, privateSection) {
1245
+ const sections = {
1246
+ public: Object.keys(publicSection),
1247
+ protected: protectedSection ? Object.keys(protectedSection) : [],
1248
+ private: privateSection ? Object.keys(privateSection) : [],
1249
+ };
1250
+ assertSectionsDisjoint(sections);
1251
+ const mod = Object.defineProperties({}, {
1252
+ ...Object.getOwnPropertyDescriptors(publicSection),
1253
+ ...Object.getOwnPropertyDescriptors(protectedSection ?? {}),
1254
+ ...Object.getOwnPropertyDescriptors(privateSection ?? {}),
1255
+ });
1256
+ Object.defineProperty(mod, moduleVisibility, { value: sections });
1257
+ return mod;
1258
+ }
1259
+ function assertSectionsDisjoint(sections) {
1260
+ const seen = new Map();
1261
+ for (const kind of ["public", "protected", "private"]) {
1262
+ for (const name of sections[kind]) {
1263
+ const first = seen.get(name);
1264
+ if (first) {
1265
+ throw new ArgumentError(`defineModule: ${name} appears in both the ${first} and ${kind} sections`);
1266
+ }
1267
+ seen.set(name, kind);
1268
+ }
1269
+ }
1270
+ }
1271
+ /**
1272
+ * Mirrors: Ruby's Module#public_instance_methods — vendor/ruby/v3.3.11/class.c:1942
1273
+ * `rb_class_public_instance_methods` — the module's public instance methods,
1274
+ * own-only when `includeSuper` is false.
1275
+ *
1276
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
1277
+ *
1278
+ * Known limitation: TypeScript's `private` / `protected` are erased at runtime,
1279
+ * so the class form cannot see them and reports every prototype member. Only a
1280
+ * `#`-private field and a `defineModule` section are visible here; enforcement
1281
+ * of the rest is a compare-time gate rather than this runtime walk.
1282
+ *
1283
+ * `includeSuper` is inert on a `Module`, whose method table is one flat table
1284
+ * of its own methods.
1285
+ */
1286
+ export function publicInstanceMethods(mod, includeSuper = true) {
1287
+ if (mod instanceof Module)
1288
+ return Object.getOwnPropertyNames(carrierOf(mod));
1289
+ if (typeof mod === "function") {
1290
+ const names = new Set();
1291
+ let proto = mod.prototype;
1292
+ while (proto && proto !== Object.prototype) {
1293
+ for (const name of Object.getOwnPropertyNames(proto)) {
1294
+ if (name !== "constructor")
1295
+ names.add(name);
1296
+ }
1297
+ if (!includeSuper)
1298
+ break;
1299
+ proto = Object.getPrototypeOf(proto);
1300
+ }
1301
+ return [...names];
1302
+ }
1303
+ const sections = mod[moduleVisibility];
1304
+ const names = sections
1305
+ ? [...sections.public]
1306
+ : Object.keys(mod).filter((name) => !/^[A-Z]/.test(name));
1307
+ if (!includeSuper)
1308
+ return names;
1309
+ for (const m of rbModAncestors(mod).slice(1)) {
1310
+ for (const name of publicInstanceMethods(m, false)) {
1311
+ if (!names.includes(name))
1312
+ names.push(name);
1313
+ }
1314
+ }
1315
+ return names;
1316
+ }
1317
+ function isClassReceiver(klass) {
1318
+ return typeof klass === "function" && !Object.hasOwn(klass, classModule);
1319
+ }
1320
+ function featureHook(mod, name) {
1321
+ if (!(mod instanceof Module)) {
1322
+ if (mod === null || (typeof mod !== "object" && typeof mod !== "function"))
1323
+ return undefined;
1324
+ const descriptor = Object.getOwnPropertyDescriptor(mod, name);
1325
+ return descriptor && !descriptor.enumerable && typeof descriptor.value === "function"
1326
+ ? descriptor.value.bind(mod)
1327
+ : undefined;
1328
+ }
1329
+ const hook = mod[name];
1330
+ if (hook === Module.prototype[name])
1331
+ return undefined;
1332
+ return typeof hook === "function" ? hook.bind(mod) : undefined;
1333
+ }
1334
+ /**
1335
+ * Mirrors: Ruby's Module#include — vendor/ruby/v3.3.11/eval.c:1139 `rb_mod_include`,
1336
+ * backed by vendor/ruby/v3.3.11/class.c:1179 `rb_include_module`.
1337
+ *
1338
+ * @noRailsEquivalent PERMANENT — a Ruby core-language primitive, which Rails
1339
+ * uses but does not define.
1340
+ */
1341
+ export function include(klass, mod) {
1342
+ if (!isClassReceiver(klass))
1343
+ markModuleObject(klass);
1344
+ markModuleObject(mod);
1345
+ const appendFeatures = featureHook(mod, "appendFeatures");
1346
+ if (appendFeatures) {
1347
+ appendFeatures(klass);
1348
+ if (typeof mod[included] === "function") {
1349
+ mod[included](klass);
1350
+ }
1351
+ else {
1352
+ featureHook(mod, "included")?.(klass);
1353
+ }
1354
+ return;
1355
+ }
1356
+ if (!isClassReceiver(klass)) {
1357
+ if (!(klass instanceof Module))
1358
+ trackIncludedModule(klass, mod, moduleIncludesKey);
1359
+ if (typeof mod[included] === "function") {
1360
+ mod[included](klass);
1361
+ }
1362
+ return;
1363
+ }
1364
+ if (isModuleMethodTablePresent(klass, mod)) {
1365
+ if (typeof mod[included] === "function") {
1366
+ mod[included](klass);
1367
+ }
1368
+ return;
1369
+ }
1370
+ rbModAppendFeatures(klass, mod);
1371
+ if (typeof mod[included] === "function") {
1372
+ mod[included](klass);
1373
+ }
1374
+ else if (!(mod instanceof Module)) {
1375
+ featureHook(mod, "included")?.(klass);
1376
+ }
1377
+ }
1378
+ /**
1379
+ * Mirrors: Ruby's Module#append_features — vendor/ruby/v3.3.11/eval.c:1110
1380
+ * `rb_mod_append_features`, the step `include` runs before `included`, which a
1381
+ * module overriding `append_features` (`ActiveSupport::Concern`) calls as
1382
+ * `super`. A plain-object module's instance methods are its enumerable own
1383
+ * members; the modules it included are appended first, as `include_modules_at`
1384
+ * (vendor/ruby/v3.3.11/class.c:1253) walks the included module's ancestry and
1385
+ * skips one `klass` already has, so the module's own methods outrank them.
1386
+ *
1387
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
1388
+ */
1389
+ export function rbModAppendFeatures(klass, mod) {
1390
+ rbClearMethodCache();
1391
+ if (!isClassReceiver(klass) && !(klass instanceof Module)) {
1392
+ return trackIncludedModule(klass, mod, moduleIncludesKey);
1393
+ }
1394
+ if (mod instanceof Module)
1395
+ return Module.prototype.appendFeatures.call(mod, klass);
1396
+ if (klass instanceof Module)
1397
+ return appendPlainFeatures(klass, mod);
1398
+ if (Object.hasOwn(mod, moduleIncludesKey)) {
1399
+ for (const nested of mod[moduleIncludesKey]) {
1400
+ if (!isModuleMethodTablePresent(klass, nested))
1401
+ include(klass, nested);
1402
+ }
1403
+ }
1404
+ trackIncludedModule(klass.prototype, mod);
1405
+ const descriptors = {};
1406
+ const installed = trackedKeys(klass.prototype);
1407
+ const skipped = [];
1408
+ const isClassModule = typeof mod === "function" && mod.prototype;
1409
+ if (isClassModule) {
1410
+ const proto = mod.prototype;
1411
+ for (const key of [
1412
+ ...Object.getOwnPropertyNames(proto),
1413
+ Symbol.iterator,
1414
+ Symbol.asyncIterator,
1415
+ ]) {
1416
+ if (key === "constructor")
1417
+ continue;
1418
+ const modDesc = Object.getOwnPropertyDescriptor(proto, key);
1419
+ if (!modDesc)
1420
+ continue;
1421
+ const existing = Object.getOwnPropertyDescriptor(klass.prototype, key);
1422
+ const existingIsMixin = installed.has(key);
1423
+ if (typeof key === "symbol") {
1424
+ if (!existing || existingIsMixin) {
1425
+ descriptors[key] = modDesc;
1426
+ installed.add(key);
1427
+ }
1428
+ else {
1429
+ skipped.push(key);
1430
+ }
1431
+ continue;
1432
+ }
1433
+ if (!existing || existingIsMixin) {
1434
+ rbSeatSuper(klass.prototype, key, modDesc.value, descriptors);
1435
+ }
1436
+ if (!existing) {
1437
+ descriptors[key] = modDesc;
1438
+ installed.add(key);
1439
+ continue;
1440
+ }
1441
+ const isAccessorPair = ("get" in modDesc || "set" in modDesc) && ("get" in existing || "set" in existing);
1442
+ if (isAccessorPair) {
1443
+ const higher = existingIsMixin ? modDesc : existing;
1444
+ const lower = existingIsMixin ? existing : modDesc;
1445
+ descriptors[key] = {
1446
+ get: higher.get ?? lower.get,
1447
+ set: higher.set ?? lower.set,
1448
+ configurable: true,
1449
+ enumerable: higher.enumerable ?? lower.enumerable ?? false,
1450
+ };
1451
+ if (existingIsMixin)
1452
+ installed.add(key);
1453
+ else if ((existing.get && modDesc.get) || (existing.set && modDesc.set)) {
1454
+ skipped.push(key);
1455
+ }
1456
+ }
1457
+ else if (existingIsMixin) {
1458
+ descriptors[key] = modDesc;
1459
+ }
1460
+ else {
1461
+ skipped.push(key);
1462
+ }
1463
+ }
1464
+ }
1465
+ else {
1466
+ for (let ancestor = mod; ancestor && ancestor !== Object.prototype;) {
1467
+ const modDescs = Object.getOwnPropertyDescriptors(ancestor);
1468
+ const namespace = ancestor[Symbol.toStringTag];
1469
+ for (const key of [...Object.keys(modDescs), Symbol.iterator, Symbol.asyncIterator]) {
1470
+ let modDesc = modDescs[key];
1471
+ if (modDesc !== undefined && namespace === "Module" && !("value" in modDesc)) {
1472
+ modDesc = { value: Reflect.get(ancestor, key), enumerable: modDesc.enumerable };
1473
+ }
1474
+ if (modDesc === undefined || (typeof key === "string" && !modDesc.enumerable))
1475
+ continue;
1476
+ if (key === "constructor" || (typeof key === "string" && /^[A-Z]/.test(key)))
1477
+ continue;
1478
+ if ("value" in modDesc && typeof modDesc.value !== "function")
1479
+ continue;
1480
+ if (Object.hasOwn(descriptors, key))
1481
+ continue;
1482
+ const origin = typeof key === "string" && typeof modDesc.value === "function"
1483
+ ? prependOrigin(klass.prototype, key)
1484
+ : undefined;
1485
+ if (origin) {
1486
+ const entry = superSlotFor(modDesc.value, String(key));
1487
+ const below = Reflect.get(klass.prototype, origin.slot);
1488
+ if (below !== undefined &&
1489
+ !installed.has(key) &&
1490
+ below !== Reflect.get(Object.getPrototypeOf(klass.prototype), key)) {
1491
+ continue;
1492
+ }
1493
+ if (below !== undefined) {
1494
+ descriptors[entry.slot] = { value: below, configurable: true };
1495
+ entry.seats = (entry.seats ?? 0) + 1;
1496
+ }
1497
+ descriptors[origin.slot] = { value: modDesc.value, configurable: true };
1498
+ installed.add(key);
1499
+ continue;
1500
+ }
1501
+ if (Object.hasOwn(klass.prototype, key) && !installed.has(key)) {
1502
+ skipped.push(key);
1503
+ continue;
1504
+ }
1505
+ installed.add(key);
1506
+ descriptors[key] = { ...modDesc, configurable: true, enumerable: false };
1507
+ if (typeof key === "string") {
1508
+ rbSeatSuper(klass.prototype, key, modDesc.value, descriptors);
1509
+ rbSeatSuper(klass.prototype, key, modDesc.get, descriptors, "get");
1510
+ rbSeatSuper(klass.prototype, key, modDesc.set, descriptors, "set");
1511
+ }
1512
+ }
1513
+ ancestor = Object.getPrototypeOf(ancestor);
1514
+ }
1515
+ }
1516
+ Object.defineProperties(klass.prototype, descriptors);
1517
+ const optOut = Object.hasOwn(klass, shadowsIncluded)
1518
+ ? klass[shadowsIncluded]
1519
+ : [];
1520
+ for (const key of skipped) {
1521
+ if (optOut.includes(key))
1522
+ continue;
1523
+ let names = displaced.get(klass.prototype);
1524
+ if (!names)
1525
+ displaced.set(klass.prototype, (names = new Map()));
1526
+ const mods = names.get(key);
1527
+ if (!mods)
1528
+ names.set(key, [mod]);
1529
+ else if (!mods.includes(mod))
1530
+ mods.push(mod);
1531
+ }
1532
+ }
1533
+ /** @noRailsEquivalent PERMANENT */
1534
+ export const shadowsIncluded = Symbol.for("@blazetrails/ruby-compat:shadowsIncluded");
1535
+ const displaced = new WeakMap();
1536
+ /** @noRailsEquivalent PERMANENT */
1537
+ export function displacedIncludedMembers(klass) {
1538
+ return new Map([...(displaced.get(klass.prototype) ?? [])].map(([k, v]) => [k, [...v]]));
1539
+ }
1540
+ const prependedMethods = new WeakMap();
1541
+ /**
1542
+ * The super slot of the lowest method prepended over `key` on `proto`, where
1543
+ * Ruby's `include` inserts a module (`include_modules_at`,
1544
+ * vendor/ruby/v3.3.11/class.c:1253, starts at the class's origin, below its
1545
+ * prepended modules). Undefined when no module is prepended over it.
1546
+ */
1547
+ function prependOrigin(proto, key) {
1548
+ const methods = prependedMethods.get(proto);
1549
+ let method = Object.getOwnPropertyDescriptor(proto, key)?.value;
1550
+ if (!methods?.has(method))
1551
+ return undefined;
1552
+ for (;;) {
1553
+ const entry = superSlotFor(method, key);
1554
+ const below = Reflect.get(proto, entry.slot);
1555
+ if (!methods.has(below))
1556
+ return entry;
1557
+ method = below;
1558
+ }
1559
+ }
1560
+ /**
1561
+ * Mirrors: Ruby's `super` — vendor/ruby/v3.3.11/vm_eval.c:366 `rb_call_super`.
1562
+ * A plain-object module's method reaches the next method of its name in the
1563
+ * includer's ancestry: the one `include()` found on the includer's prototype
1564
+ * when it copied `method` there, seated under `method`'s own slot. With none
1565
+ * seated, the search ends in `Kernel`, where every Ruby ancestry ends.
1566
+ *
1567
+ * A function seated at two places in one ancestry (a module included into a
1568
+ * class and then into its superclass below a prepend, both copies kept by
1569
+ * `include_modules_at`, vendor/ruby/v3.3.11/class.c:1253) has one slot, so
1570
+ * the lower copy's seat shadows the upper one's; the upper copy's seat is
1571
+ * read off the link it was found at. MRI runs the upper copy a second time
1572
+ * (`["mod", "prepended", "mod", "base"]` for the subclass in ruby 3.3.11);
1573
+ * trails skips it, since one function's slot cannot answer from two ancestry
1574
+ * positions and an awaited body carries no frame to tell the copies apart.
1575
+ *
1576
+ * @inventedArm skip — PERMANENT
1577
+ * @noRailsEquivalent PERMANENT
1578
+ */
1579
+ export function rbCallSuper(receiver, method, ...args) {
1580
+ let slot = method[_superSlot];
1581
+ let entry;
1582
+ if (slot === undefined)
1583
+ slot = (entry = superSlots.get(method))?.slot;
1584
+ let next = slot === undefined ? undefined : receiver[slot];
1585
+ for (let nextEntry; slot !== undefined && typeof next === "function" && _superSlot in next;) {
1586
+ nextEntry = superSlots.get(next);
1587
+ if (nextEntry === undefined || (nextEntry.seats ?? 0) < 2)
1588
+ break;
1589
+ let holder = receiver;
1590
+ while (holder && !Object.hasOwn(holder, slot))
1591
+ holder = Object.getPrototypeOf(holder);
1592
+ let own = receiver;
1593
+ while (own && !Object.hasOwn(own, nextEntry.slot))
1594
+ own = Object.getPrototypeOf(own);
1595
+ if (!holder || !own || own === holder || !Object.prototype.isPrototypeOf.call(holder, own))
1596
+ break;
1597
+ slot = nextEntry.slot;
1598
+ entry = nextEntry;
1599
+ next = Reflect.get(holder, slot, receiver);
1600
+ }
1601
+ if (next === undefined) {
1602
+ const name = (entry ?? superSlots.get(method))?.key ?? method.name;
1603
+ if (Object.hasOwn(Kernel, name))
1604
+ next = Reflect.get(Kernel, name);
1605
+ }
1606
+ if (typeof next !== "function") {
1607
+ throw new NoMethodError(`super: no superclass method '${method.name}' for an instance of ${receiver.constructor.name}`, method.name);
1608
+ }
1609
+ return next.apply(receiver, args);
1610
+ }
1611
+ /**
1612
+ * Mirrors: Ruby's Object#clone — vendor/ruby/v3.3.11/object.c:536 `rb_obj_clone`, via
1613
+ * `rb_obj_clone_setup` (:457-527): a new object of the same class carrying a
1614
+ * copy of the receiver's singleton class and instance variables (`init_copy`),
1615
+ * then `initialize_clone(orig)` dispatched on the copy, which is frozen after
1616
+ * that hook runs when the receiver is. The singleton class is copied, not
1617
+ * shared, so the clone's `extend()` registries are its own. A JS primitive is
1618
+ * MRI's `special_object_p` (:380-393) and is returned as is (:539), as is a
1619
+ * Temporal value; an array is allocated as one (`rb_obj_alloc`), so its
1620
+ * elements, which Ruby copies in `Array#initialize_copy` (`array.c:8613`,
1621
+ * `rb_ary_replace`), land on a real array, and so are a JS `Date`, `Map`, `Set`,
1622
+ * `RegExp` and typed array. A typed array is copied through the constructor
1623
+ * its `Symbol.toStringTag` names, since a Node `Buffer`'s `slice` answers a
1624
+ * view onto the same memory and its own constructor is the deprecated
1625
+ * `Buffer()`. A class with an allocator ({@link rbDefineAllocFunc}) is
1626
+ * allocated through it. The copy hook is found as a method entry.
1627
+ *
1628
+ * Ruby's `Object#initialize_clone` / `#initialize_dup` default to
1629
+ * `initialize_copy` (`rb_obj_init_clone` / `rb_obj_init_dup_clone`, object.c:4382-4383), so a
1630
+ * receiver that defines only `initializeCopy` gets it here. This and
1631
+ * {@link rbObjDup} are the one spelling of Ruby `obj.clone` / `obj.dup`; a
1632
+ * class ports `initialize_clone` / `initialize_dup` / `initialize_copy` at
1633
+ * their Rails names and never open-codes the copy.
1634
+ *
1635
+ * @noRailsEquivalent PERMANENT — a Ruby core-language primitive, which Rails
1636
+ * uses but does not define.
1637
+ */
1638
+ export function rbObjClone(obj) {
1639
+ if (obj === null || (typeof obj !== "object" && typeof obj !== "function"))
1640
+ return obj;
1641
+ if (temporalTag(obj) !== null)
1642
+ return obj;
1643
+ const frozen = Object.isFrozen(obj);
1644
+ const descriptors = copiedDescriptors(obj, frozen);
1645
+ for (const registry of [extendedKeys, includedModulesKey]) {
1646
+ const table = descriptors[registry];
1647
+ if (table)
1648
+ descriptors[registry] = { ...table, value: new Set(table.value) };
1649
+ }
1650
+ const alloc = rbObjAlloc(obj, Object.getPrototypeOf(obj));
1651
+ if (isClassConstructor(obj))
1652
+ copyMethodTable(obj, alloc, descriptors);
1653
+ const clone = Object.defineProperties(alloc, descriptors);
1654
+ const defined = extendedOwners.get(obj);
1655
+ if (defined)
1656
+ extendedOwners.set(clone, new Map(defined));
1657
+ initCopyHook(clone, "initializeClone", obj);
1658
+ if (frozen)
1659
+ Object.freeze(clone);
1660
+ return clone;
1661
+ }
1662
+ /**
1663
+ * Mirrors: Ruby's Object#dup — vendor/ruby/v3.3.11/object.c:591 `rb_obj_dup`, via
1664
+ * `rb_obj_dup_setup` (:543-549): a new object of `rb_obj_class(obj)` — the
1665
+ * singleton class and the modules it was `extend`ed with are not carried —
1666
+ * holding a copy of the instance variables, then `initialize_dup(orig)`
1667
+ * dispatched on the copy. The frozen state is not carried either. A primitive
1668
+ * and an array are handled as in {@link rbObjClone}.
1669
+ *
1670
+ * @noRailsEquivalent PERMANENT — a Ruby core-language primitive, which Rails
1671
+ * uses but does not define.
1672
+ */
1673
+ export function rbObjDup(obj) {
1674
+ if (obj === null || (typeof obj !== "object" && typeof obj !== "function"))
1675
+ return obj;
1676
+ if (temporalTag(obj) !== null)
1677
+ return obj;
1678
+ const descriptors = copiedDescriptors(obj, true);
1679
+ const singletonKeys = Object.hasOwn(obj, extendedKeys)
1680
+ ? obj[extendedKeys]
1681
+ : undefined;
1682
+ if (!isClassConstructor(obj)) {
1683
+ for (const key of [extendedKeys, includedModulesKey, ...(singletonKeys ?? [])]) {
1684
+ delete descriptors[key];
1685
+ }
1686
+ }
1687
+ let proto = Object.getPrototypeOf(obj);
1688
+ if (proto !== null && Object.hasOwn(proto, FL_SINGLETON)) {
1689
+ proto = Object.getPrototypeOf(proto);
1690
+ }
1691
+ const alloc = rbObjAlloc(obj, proto);
1692
+ if (isClassConstructor(obj))
1693
+ copyMethodTable(obj, alloc, descriptors);
1694
+ const dup = Object.defineProperties(alloc, descriptors);
1695
+ initCopyHook(dup, "initializeDup", obj);
1696
+ return dup;
1697
+ }
1698
+ const allocFuncs = new WeakMap();
1699
+ /**
1700
+ * `rb_define_alloc_func` (`vendor/ruby/v3.3.11/vm_method.c:1270`): the allocator
1701
+ * for `klass` and its subclasses (`rb_get_alloc_func`, `:1286`), declared when
1702
+ * instances hold state `Object.create` cannot make (`#private` fields, a Proxy).
1703
+ *
1704
+ * @noRailsEquivalent PERMANENT
1705
+ */
1706
+ export function rbDefineAllocFunc(klass, func) {
1707
+ allocFuncs.set(klass, func);
1708
+ }
1709
+ /**
1710
+ * `rb_get_alloc_func` (`vendor/ruby/v3.3.11/vm_method.c:1286`).
1711
+ *
1712
+ * @noRailsEquivalent PERMANENT
1713
+ */
1714
+ export function rbGetAllocFunc(klass) {
1715
+ for (; typeof klass === "function"; klass = Object.getPrototypeOf(klass)) {
1716
+ const allocator = allocFuncs.get(klass);
1717
+ if (allocator)
1718
+ return allocator;
1719
+ }
1720
+ }
1721
+ /**
1722
+ * `rb_class_new_instance` (`vendor/ruby/v3.3.11/object.c:2158`), `Class#new`:
1723
+ * allocate, then `initialize` with `args`. A JS constructor is both halves, so
1724
+ * a class is built with `new`, reached past a `protected` constructor; that is
1725
+ * how a `static async new` builds `this`, and why its result is typed as the
1726
+ * receiver's instance. `empty_hash_alloc` (`vendor/ruby/v3.3.11/hash.c:1488`)
1727
+ * is a `Hash`, and a String is a primitive (CLAUDE.md, "Ruby Strings are JS
1728
+ * string primitives"), so `empty_str_alloc`
1729
+ * (`vendor/ruby/v3.3.11/string.c:858`) is `""`. `Class.new` is an anonymous
1730
+ * class (`rb_class_initialize`, `vendor/ruby/v3.3.11/object.c:2007`), and
1731
+ * `Regexp.new` takes one to three arguments (`rb_reg_initialize_m`,
1732
+ * `vendor/ruby/v3.3.11/re.c:3957`).
1733
+ *
1734
+ * @noRailsEquivalent PERMANENT
1735
+ */
1736
+ export function rbClassNewInstance(klass, ...args) {
1737
+ if (klass === Hash)
1738
+ return new Hash();
1739
+ if (klass === rbCString)
1740
+ return "";
1741
+ if (klass === rbCClass)
1742
+ return class {
1743
+ };
1744
+ if (klass === RegExp && args.length === 0) {
1745
+ throw new ArgumentError("wrong number of arguments (given 0, expected 1..3)");
1746
+ }
1747
+ return new klass(...args);
1748
+ }
1749
+ function classAlloc(orig, superclass) {
1750
+ const clone = function (...args) {
1751
+ if (new.target === undefined) {
1752
+ throw new TypeError("Class constructor cannot be invoked without 'new'");
1753
+ }
1754
+ return Reflect.construct(orig, args, new.target);
1755
+ };
1756
+ return Object.setPrototypeOf(clone, superclass);
1757
+ }
1758
+ function copyMethodTable(orig, clone, descriptors) {
1759
+ const mTbl = Object.getOwnPropertyDescriptors(orig.prototype);
1760
+ Object.defineProperty(mTbl, "constructor", {
1761
+ value: { ...Object.getOwnPropertyDescriptor(orig.prototype, "constructor"), value: clone },
1762
+ enumerable: true,
1763
+ });
1764
+ const table = mTbl[includedModulesKey];
1765
+ if (table)
1766
+ mTbl[includedModulesKey] = { ...table, value: new Set(table.value) };
1767
+ descriptors["prototype"] = {
1768
+ value: Object.create(Object.getPrototypeOf(orig.prototype), mTbl),
1769
+ writable: false,
1770
+ enumerable: false,
1771
+ configurable: false,
1772
+ };
1773
+ descriptors["name"] = { ...descriptors["name"], value: "" };
1774
+ }
1775
+ function isClassConstructor(obj) {
1776
+ return (typeof obj === "function" &&
1777
+ Object.getOwnPropertyDescriptor(obj, "prototype")?.writable === false);
1778
+ }
1779
+ function rbObjAlloc(obj, proto) {
1780
+ if (isClassConstructor(obj))
1781
+ return classAlloc(obj, proto);
1782
+ const klass = proto?.constructor;
1783
+ const allocator = rbGetAllocFunc(klass);
1784
+ if (allocator)
1785
+ return Object.setPrototypeOf(allocator(klass), proto);
1786
+ if (Array.isArray(obj))
1787
+ return Object.setPrototypeOf([], proto);
1788
+ if (obj instanceof Date)
1789
+ return Object.setPrototypeOf(new Date(obj.getTime()), proto);
1790
+ if (obj instanceof Map)
1791
+ return Object.setPrototypeOf(new Map(obj), proto);
1792
+ if (obj instanceof Set)
1793
+ return Object.setPrototypeOf(new Set(obj), proto);
1794
+ if (obj instanceof RegExp)
1795
+ return Object.setPrototypeOf(new RegExp(obj), proto);
1796
+ if (ArrayBuffer.isView(obj) && !(obj instanceof DataView)) {
1797
+ const typedArray = globalThis[obj[Symbol.toStringTag]];
1798
+ return Object.setPrototypeOf(new typedArray(obj), proto);
1799
+ }
1800
+ return Object.create(proto);
1801
+ }
1802
+ function copiedDescriptors(obj, unfreeze) {
1803
+ const descriptors = Object.getOwnPropertyDescriptors(obj);
1804
+ if (unfreeze) {
1805
+ for (const key of Reflect.ownKeys(descriptors)) {
1806
+ const descriptor = descriptors[key];
1807
+ descriptor.configurable = !((key === "length" && Array.isArray(obj)) ||
1808
+ (key === "lastIndex" && obj instanceof RegExp));
1809
+ if (!descriptor.get && !descriptor.set)
1810
+ descriptor.writable = true;
1811
+ }
1812
+ }
1813
+ return descriptors;
1814
+ }
1815
+ function initCopyHook(copy, hook, orig) {
1816
+ for (const mid of [hook, "initializeCopy"]) {
1817
+ for (let o = copy; o; o = Object.getPrototypeOf(o)) {
1818
+ const me = Object.getOwnPropertyDescriptor(o, mid);
1819
+ if (!me)
1820
+ continue;
1821
+ if (typeof me.value !== "function")
1822
+ break;
1823
+ me.value.call(copy, orig);
1824
+ return;
1825
+ }
1826
+ }
1827
+ }
1828
+ /**
1829
+ * Ruby-style `prepend` for mixing module methods into a class *above* it.
1830
+ *
1831
+ * Ruby's `prepend` inserts the module ahead of the class in the ancestry, so a
1832
+ * method the module defines wins over the same method in the class body — the
1833
+ * one behavioural difference from `include`, which loses to it. Here that is a
1834
+ * plain assignment onto the class prototype.
1835
+ *
1836
+ * The method it replaces is seated under the module method's super slot, so
1837
+ * the module reaches it with {@link rbCallSuper}, as Ruby's `super` does.
1838
+ *
1839
+ * A module whose method table is already in the ancestry is skipped
1840
+ * whole, the way `include_modules_at` skips one
1841
+ * (vendor/ruby/v3.3.11/class.c:1281,1291,1296).
1842
+ *
1843
+ * Mirrors: Ruby's Module#prepend — vendor/ruby/v3.3.11/eval.c:1196 `rb_mod_prepend`,
1844
+ * backed by vendor/ruby/v3.3.11/class.c:1430 `rb_prepend_module`.
1845
+ *
1846
+ * @noRailsEquivalent PERMANENT — a Ruby core-language primitive, which Rails
1847
+ * uses but does not define.
1848
+ */
1849
+ export function prepend(target, mod) {
1850
+ const klass = target;
1851
+ if (!isClassReceiver(klass))
1852
+ markModuleObject(klass);
1853
+ markModuleObject(mod);
1854
+ const prependFeatures = featureHook(mod, "prependFeatures");
1855
+ if (prependFeatures) {
1856
+ prependFeatures(klass);
1857
+ if (typeof mod[prepended] === "function") {
1858
+ mod[prepended](klass);
1859
+ }
1860
+ else {
1861
+ featureHook(mod, "prepended")?.(klass);
1862
+ }
1863
+ return;
1864
+ }
1865
+ if (!isModuleMethodTablePresent(klass, mod))
1866
+ rbModPrependFeatures(klass, mod);
1867
+ if (typeof mod[prepended] === "function") {
1868
+ mod[prepended](klass);
1869
+ }
1870
+ else if (!(mod instanceof Module)) {
1871
+ featureHook(mod, "prepended")?.(klass);
1872
+ }
1873
+ }
1874
+ /**
1875
+ * Mirrors: Ruby's Module#prepend_features — vendor/ruby/v3.3.11/eval.c:1175
1876
+ * `rb_mod_prepend_features`, the step `prepend` runs before `prepended`, which
1877
+ * `ActiveSupport::Concern#prepend_features` calls as `super`. A plain-object
1878
+ * module's non-enumerable members are its singleton methods, which `extend`
1879
+ * installs, so only its enumerable members are prepended.
1880
+ *
1881
+ * @noRailsEquivalent PERMANENT — a Ruby core method, not a Rails one.
1882
+ */
1883
+ export function rbModPrependFeatures(klass, mod) {
1884
+ rbClearMethodCache();
1885
+ if (mod instanceof Module)
1886
+ return Module.prototype.prependFeatures.call(mod, klass);
1887
+ if (Object.hasOwn(mod, moduleIncludesKey)) {
1888
+ for (const nested of mod[moduleIncludesKey]) {
1889
+ if (!isModuleMethodTablePresent(klass, nested))
1890
+ prepend(klass, nested);
1891
+ }
1892
+ }
1893
+ trackIncludedModule(klass.prototype, mod);
1894
+ const source = typeof mod === "function" ? mod.prototype : mod;
1895
+ const seated = {};
1896
+ for (const key of Object.getOwnPropertyNames(source)) {
1897
+ if (key === "constructor")
1898
+ continue;
1899
+ const descriptor = Object.getOwnPropertyDescriptor(source, key);
1900
+ if (descriptor && (typeof mod === "function" || descriptor.enumerable)) {
1901
+ rbSeatSuper(klass.prototype, key, descriptor.value, seated);
1902
+ Object.defineProperty(klass.prototype, key, descriptor);
1903
+ if (typeof descriptor.value === "function") {
1904
+ let methods = prependedMethods.get(klass.prototype);
1905
+ if (!methods)
1906
+ prependedMethods.set(klass.prototype, (methods = new Set()));
1907
+ methods.add(descriptor.value);
1908
+ }
1909
+ }
1910
+ }
1911
+ Object.defineProperties(klass.prototype, seated);
1912
+ }
1913
+ /**
1914
+ * Ruby-style `extend` for mixing module methods onto a class as static methods.
1915
+ *
1916
+ * In Ruby, `extend SomeModule` copies the module's methods onto the
1917
+ * object itself (not its prototype). When used on a class, this makes
1918
+ * the methods available as class-level (static) methods.
1919
+ *
1920
+ * Precedence follows Ruby's singleton ancestry, the way `include()`'s does on
1921
+ * the instance side: `include SomeModule` puts `SomeModule::ClassMethods`
1922
+ * BELOW the class body (concern.rb:135-138), so a class-body `static` wins over
1923
+ * the module's member of that name, while a later `extend()` wins over an
1924
+ * earlier one. Accessor halves are resolved independently, since Ruby reads a
1925
+ * getter (`key`) and a setter (`key=`) as two methods where TypeScript shares
1926
+ * one property name between them. The `name` a class is born with, declared
1927
+ * or an expression, is not a method its body defines: it stands for
1928
+ * `Module#name`, which a module method on the singleton class is found before,
1929
+ * so a module's `name` replaces it. A born `name` is the non-writable one; a
1930
+ * `static name` field or accessor the class body declares is not, and wins.
1931
+ *
1932
+ * Mirrors: Ruby's Object#extend — vendor/ruby/v3.3.11/eval.c:1778 `rb_obj_extend`,
1933
+ * which returns the receiver (:1800). `rb_extend_object` (:1713-1716) is
1934
+ * `rb_include_module` on the receiver's singleton class, so the module's
1935
+ * ancestors come with it: a plain-object module's prototype chain is walked,
1936
+ * nearest first, as `include()` walks it.
1937
+ *
1938
+ * @noRailsEquivalent PERMANENT — a Ruby core-language primitive, which Rails
1939
+ * uses but does not define.
1940
+ *
1941
+ * Usage:
1942
+ * extend(Base, ConnectionHandlingMethods);
1943
+ * // Now Base.connectedTo(...) works
1944
+ */
1945
+ export function extend(klass, ...argv) {
1946
+ let argc = argv.length;
1947
+ if (argc < 1) {
1948
+ throw new ArgumentError(`wrong number of arguments (given ${argc}, expected 1+)`);
1949
+ }
1950
+ rbClearMethodCache();
1951
+ while (argc--) {
1952
+ extendObject(klass, argv[argc]);
1953
+ }
1954
+ return klass;
1955
+ }
1956
+ function extendObject(klass, mod) {
1957
+ markModuleObject(mod);
1958
+ const extendedHook = featureHook(mod, "extended");
1959
+ if (extendedHook) {
1960
+ extendedHook(klass);
1961
+ return;
1962
+ }
1963
+ if (mod instanceof Module) {
1964
+ mod.extendObject(klass);
1965
+ return;
1966
+ }
1967
+ if (Object.hasOwn(mod, moduleIncludesKey)) {
1968
+ for (const nested of mod[moduleIncludesKey]) {
1969
+ if (singletonSearchAncestor(klass, nested))
1970
+ continue;
1971
+ if (typeof nested !== "function") {
1972
+ extendObject(klass, nested);
1973
+ continue;
1974
+ }
1975
+ const methods = {};
1976
+ for (let link = nested.prototype; link && link !== Object.prototype; link = Object.getPrototypeOf(link)) {
1977
+ for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(link))) {
1978
+ if (key !== "constructor" && !Object.hasOwn(methods, key))
1979
+ methods[key] = descriptor;
1980
+ }
1981
+ }
1982
+ for (const descriptor of Object.values(methods))
1983
+ descriptor.enumerable = true;
1984
+ const table = Object.defineProperties({}, methods);
1985
+ extendObject(klass, table);
1986
+ klass[includedModulesKey].delete(table);
1987
+ trackIncludedModule(klass, nested);
1988
+ if (typeof klass !== "function") {
1989
+ const singleton = rbObjSingletonClass(klass).prototype;
1990
+ singleton[includedModulesKey].delete(table);
1991
+ trackIncludedModule(singleton, nested);
1992
+ }
1993
+ }
1994
+ }
1995
+ const isClassModule = typeof mod === "function" && mod.prototype;
1996
+ const owners = new Map();
1997
+ if (isClassModule && Object.hasOwn(mod, classModule)) {
1998
+ const proto = mod.prototype;
1999
+ for (const key of Object.getOwnPropertyNames(proto)) {
2000
+ if (key !== "constructor")
2001
+ owners.set(key, proto);
2002
+ }
2003
+ }
2004
+ else if (isClassModule) {
2005
+ for (const key of Object.getOwnPropertyNames(mod)) {
2006
+ if (!STATIC_CLASS_KEYS.has(key))
2007
+ owners.set(key, mod);
2008
+ }
2009
+ }
2010
+ else {
2011
+ for (let ancestor = mod; ancestor && ancestor !== Object.prototype; ancestor = Object.getPrototypeOf(ancestor)) {
2012
+ for (const key of Object.keys(ancestor)) {
2013
+ if (!owners.has(key))
2014
+ owners.set(key, ancestor);
2015
+ }
2016
+ }
2017
+ }
2018
+ const installed = trackedKeys(klass, extendedKeys);
2019
+ let defined = extendedOwners.get(klass);
2020
+ if (!defined)
2021
+ extendedOwners.set(klass, (defined = new Map()));
2022
+ for (const [key, owner] of owners) {
2023
+ const modDesc = Object.getOwnPropertyDescriptor(owner, key);
2024
+ if (!modDesc || /^[A-Z]/.test(key))
2025
+ continue;
2026
+ if (!modDesc.get && !modDesc.set && typeof modDesc.value !== "function")
2027
+ continue;
2028
+ const own = Object.getOwnPropertyDescriptor(klass, key);
2029
+ const existing = key === "name" && own?.writable === false ? undefined : own;
2030
+ const writer = `${key}=`;
2031
+ const getterIsMixin = installed.has(key);
2032
+ const setterIsMixin = installed.has(writer);
2033
+ const modIsAccessor = modDesc.get != null || modDesc.set != null;
2034
+ const descriptor = modIsAccessor
2035
+ ? { get: modDesc.get, set: modDesc.set, configurable: true, enumerable: false }
2036
+ : { value: modDesc.value, writable: true, configurable: true, enumerable: false };
2037
+ if (!existing || getterIsMixin) {
2038
+ const seated = {};
2039
+ rbSeatSuper(klass, key, modDesc.value, seated);
2040
+ Object.defineProperties(klass, seated);
2041
+ }
2042
+ if (!existing) {
2043
+ Object.defineProperty(klass, key, descriptor);
2044
+ defined.set(key, owner);
2045
+ if (!modIsAccessor || modDesc.get != null)
2046
+ installed.add(key);
2047
+ if (modDesc.set != null)
2048
+ installed.add(writer);
2049
+ continue;
2050
+ }
2051
+ const existingIsAccessor = existing.get != null || existing.set != null;
2052
+ if (modIsAccessor && existingIsAccessor) {
2053
+ const takeGetter = modDesc.get != null && (existing.get == null || getterIsMixin);
2054
+ const takeSetter = modDesc.set != null && (existing.set == null || setterIsMixin);
2055
+ Object.defineProperty(klass, key, {
2056
+ get: takeGetter ? modDesc.get : existing.get,
2057
+ set: takeSetter ? modDesc.set : existing.set,
2058
+ configurable: true,
2059
+ enumerable: false,
2060
+ });
2061
+ if (takeGetter) {
2062
+ installed.add(key);
2063
+ defined.set(key, owner);
2064
+ }
2065
+ if (takeSetter)
2066
+ installed.add(writer);
2067
+ }
2068
+ else if (getterIsMixin && (!existingIsAccessor || existing.set == null || setterIsMixin)) {
2069
+ Object.defineProperty(klass, key, descriptor);
2070
+ defined.set(key, owner);
2071
+ if (modDesc.set != null)
2072
+ installed.add(writer);
2073
+ }
2074
+ }
2075
+ trackIncludedModule(klass, mod);
2076
+ if (typeof klass !== "function")
2077
+ trackIncludedModule(rbObjSingletonClass(klass).prototype, mod);
2078
+ if (typeof mod[extended] === "function") {
2079
+ mod[extended](klass);
2080
+ }
2081
+ }
2082
+ /**
2083
+ * Ruby's `Kernel`, the module `Object` includes and so the last stop of every
2084
+ * method search. It holds the instance methods a module's `super` reaches when
2085
+ * nothing beneath it in the receiver's ancestry defines one: `initialize_dup`
2086
+ * and `initialize_clone` (vendor/ruby/v3.3.11/object.c:654
2087
+ * `rb_obj_init_dup_clone` and :671 `rb_obj_init_clone`, which send
2088
+ * `initialize_copy`, whose default is :634 `rb_obj_init_copy`; `initialize_clone`'s `freeze:` keyword is not ported) and `freeze` (vendor/ruby/v3.3.11/object.c:1284
2089
+ * `rb_obj_freeze`), defined at vendor/ruby/v3.3.11/object.c:4382,4385. A gem that reopens
2090
+ * `Object` defines its method here, as ActiveSupport does for `as_json`.
2091
+ * `abort` is the module function `Kernel.abort` (`rb_f_abort`,
2092
+ * vendor/ruby/v3.3.11/process.c:4536), and `rand` the module function `Kernel.rand`
2093
+ * (`rb_f_rand`, vendor/ruby/v3.3.11/random.c:1684, defined at :1840), and `require`
2094
+ * `Kernel#require` (`rb_f_require`, vendor/ruby/v3.3.11/load.c:1022), each seated by
2095
+ * `index.ts`, which loads every module involved. A gem that decorates `require`
2096
+ * (Zeitwerk's `core_ext/kernel.rb`) reassigns that seat.
2097
+ *
2098
+ * @noRailsEquivalent PERMANENT
2099
+ */
2100
+ export const Kernel = {
2101
+ /** @noRailsEquivalent PERMANENT */
2102
+ dup() {
2103
+ return rbObjDup(this);
2104
+ },
2105
+ /** @noRailsEquivalent PERMANENT */
2106
+ initializeCopy(orig) {
2107
+ if (this === orig)
2108
+ return this;
2109
+ if (Object.isFrozen(this)) {
2110
+ throw new FrozenError(`can't modify frozen ${this.constructor.name}: ${rbInspect(this)}`, {
2111
+ receiver: this,
2112
+ });
2113
+ }
2114
+ if (typeof this !== typeof orig || this.constructor !== orig?.constructor) {
2115
+ throw new TypeError("initialize_copy should take same class object");
2116
+ }
2117
+ return this;
2118
+ },
2119
+ /** @noRailsEquivalent PERMANENT */
2120
+ initializeDup(orig) {
2121
+ const initializeCopy = this.initializeCopy;
2122
+ if (typeof initializeCopy === "function")
2123
+ initializeCopy.call(this, orig);
2124
+ return this;
2125
+ },
2126
+ /** @noRailsEquivalent PERMANENT */
2127
+ initializeClone(orig) {
2128
+ const initializeCopy = this.initializeCopy;
2129
+ if (typeof initializeCopy === "function")
2130
+ initializeCopy.call(this, orig);
2131
+ return this;
2132
+ },
2133
+ /** @noRailsEquivalent PERMANENT */
2134
+ freeze() {
2135
+ return Object.freeze(this);
2136
+ },
2137
+ };
2138
+ classpaths.set(Kernel, { path: "Kernel", permanent: true });
2139
+ Kernel.abort = abort;
2140
+ classpaths.set(Enumerable, { path: "Enumerable", permanent: true });
2141
+ // `rb_mComparable` (`vendor/ruby/v3.3.11/compar.c:315`).
2142
+ const rbMComparable = {};
2143
+ classpaths.set(rbMComparable, { path: "Comparable", permanent: true });
2144
+ /**
2145
+ * `rb_cModule` (`vendor/ruby/v3.3.11/object.c:4202`), `Class`'s superclass.
2146
+ * @noRailsEquivalent PERMANENT
2147
+ */
2148
+ export const rbCModule = Module;
2149
+ Object.setPrototypeOf(rbCClass, Module);
2150
+ Object.setPrototypeOf(rbCClass.prototype, Module.prototype);
2151
+ rbDefineAllocFunc(Rational, (klass) => new klass(0, 1));
2152
+ rbDefineAllocFunc(Hash, (klass) => new klass());
2153
+ classpaths.set(Rational, { path: "Rational", permanent: true });
2154
+ rbSetClassPathString(Rational.compatible, Rational, "compatible");
2155
+ for (const klass of [Rational, Complex, BigDecimal]) {
2156
+ Object.setPrototypeOf(klass, rbCNumeric);
2157
+ Object.setPrototypeOf(klass.prototype, rbCNumeric.prototype);
2158
+ }
2159
+ /**
2160
+ * `Integer#to_r` (`vendor/ruby/v3.3.11/rational.c:2148`).
2161
+ * @noRailsEquivalent PERMANENT
2162
+ */
2163
+ rbModDefineMethod(rbCInteger, "toR", function () {
2164
+ return new Rational(this, 1);
2165
+ });
2166
+ /**
2167
+ * `Integer#to_int` (`vendor/ruby/v3.3.11/numeric.rb:255`).
2168
+ * @noRailsEquivalent PERMANENT
2169
+ */
2170
+ rbModDefineMethod(rbCInteger, "toInt", function () {
2171
+ return this;
2172
+ });
2173
+ /**
2174
+ * `Float#to_r` (`vendor/ruby/v3.3.11/rational.c:2199`).
2175
+ * @noRailsEquivalent PERMANENT
2176
+ */
2177
+ rbModDefineMethod(rbCFloat, "toR", function () {
2178
+ return new Rational(Number(this), 1);
2179
+ });
2180
+ /**
2181
+ * `Float#to_int` (`vendor/ruby/v3.3.11/numeric.c:2597`).
2182
+ * @noRailsEquivalent PERMANENT
2183
+ */
2184
+ rbModDefineMethod(rbCFloat, "toInt", function () {
2185
+ return toI(Number(this));
2186
+ });
2187
+ include(rbCNumeric, rbMComparable);
2188
+ include(rbCString, rbMComparable);
2189
+ include(rbCTime, rbMComparable);
2190
+ include(rbCDate, rbMComparable);
2191
+ include(Hash, Enumerable);
2192
+ Object.defineProperty(Hash.prototype, Symbol.for("@blazetrails/ruby-compat:HASH_CLASS_BODY"), {
2193
+ value: new Set(Object.getOwnPropertyNames(Hash.prototype)),
2194
+ });
2195
+ //# sourceMappingURL=include.js.map