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

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