Skip to content

Commit 72f14dc

Browse files
docs: Add alternative example without ES Modules
1 parent 84671e1 commit 72f14dc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/cheat_sheet.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,30 @@ If you want to control Ruby VM from JavaScript, you can use `@ruby/wasm-wasi` pa
6464
</html>
6565
```
6666

67+
<details>
68+
<summary>Alternative: Without ES Modules</summary>
69+
70+
```html
71+
<html>
72+
<script src="https://cdn.jsdelivr.net/npm/@ruby/[email protected]/dist/browser.umd.js"></script>
73+
<script>
74+
const main = async () => {
75+
const { DefaultRubyVM } = window["ruby-wasm-wasi"];
76+
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/[email protected]/dist/ruby+stdlib.wasm");
77+
const module = await WebAssembly.compileStreaming(response);
78+
const { vm } = await DefaultRubyVM(module);
79+
80+
vm.eval(`
81+
require "js"
82+
JS.global[:document].write "Hello, world!"
83+
`);
84+
}
85+
main()
86+
</script>
87+
</html>
88+
```
89+
</details>
90+
6791
## Use JavaScript from Ruby
6892

6993
### Get/set JavaScript variables from Ruby

0 commit comments

Comments
 (0)