Skip to content

Commit

Permalink
docs: Add alternative example without ES Modules
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Dec 14, 2023
1 parent 84671e1 commit 72f14dc
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/cheat_sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ If you want to control Ruby VM from JavaScript, you can use `@ruby/wasm-wasi` pa
</html>
```

<details>
<summary>Alternative: Without ES Modules</summary>

```html
<html>
<script src="https://cdn.jsdelivr.net/npm/@ruby/[email protected]/dist/browser.umd.js"></script>
<script>
const main = async () => {
const { DefaultRubyVM } = window["ruby-wasm-wasi"];
const response = await fetch("https://cdn.jsdelivr.net/npm/@ruby/[email protected]/dist/ruby+stdlib.wasm");
const module = await WebAssembly.compileStreaming(response);
const { vm } = await DefaultRubyVM(module);
vm.eval(`
require "js"
JS.global[:document].write "Hello, world!"
`);
}
main()
</script>
</html>
```
</details>

## Use JavaScript from Ruby

### Get/set JavaScript variables from Ruby
Expand Down

0 comments on commit 72f14dc

Please sign in to comment.