mrubyedge 1.1.9

mruby/edge is yet another mruby that is specialized for running on WASM
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
# mruby/edge — Built-in Class & Method Coverage

A list of currently supported classes and methods, based on the implementations in `mrubyedge/src/yamrb/prelude/`.

> **Legend**
> - `.method` — class method (`self.method`)
> - `#method` — instance method
> - `(alias: x)` — also available under this name
> - `[feature: xxx]` — requires the corresponding Cargo feature flag

---

## Object (base of all classes)

`prelude/object.rs`

### Instance methods

| Method | Notes |
|---|---|
| `#initialize` | |
| `#==` | |
| `#!=` | |
| `#===` | |
| `#object_id` | alias: `__id__` |
| `#to_s` | |
| `#inspect` | |
| `#raise` | |
| `#nil?` | |
| `#lambda` | alias: `proc` |
| `#is_a?` | alias: `kind_of?` |
| `#class` | |
| `#<=>` | |
| `#method_missing` | |
| `#extend` | |
| `#loop` | |
| `#block_given?` | |
| `#respond_to?` | |
| `#public_send` | |
| `#wasm?` | mruby/edge specific |
| `#puts` | `[feature: wasi]` only |
| `#p` | `[feature: wasi]` only |
| `#debug` | `[feature: wasi]` only |

### Predefined constants

| Constant | Value |
|---|---|
| `RUBY_VERSION` | VM VERSION string |
| `MRUBY_VERSION` | same as above |
| `MRUBY_EDGE_VERSION` | same as above |
| `RUBY_ENGINE` | VM ENGINE string |

---

## Exception hierarchy

`prelude/exception.rs`

Defined classes (with inheritance):

```
Exception
├── InternalError
├── NoMemoryError
├── ScriptError
│   └── LoadError
├── SyntaxError
├── SignalException
│   └── Interrupt
├── SystemExit
├── SystemStackError
└── StandardError
    ├── RuntimeError
    ├── TypeError
    ├── ArgumentError
    ├── RangeError
    ├── ZeroDivisionError
    ├── NotImplementedError
    ├── SecurityError
    ├── SystemCallError
    ├── NoMethodError
    └── NameError
```

### Instance methods (Exception)

| Method | Notes |
|---|---|
| `#message` | |

---

## Module

`prelude/module.rs`

| Method | Notes |
|---|---|
| `#include` | |
| `#ancestors` | |

---

## Class (subclass of Module)

`prelude/class.rs`

| Method | Notes |
|---|---|
| `#new` | creates a new instance |
| `#attr_reader` | |
| `#attr_writer` | |
| `#attr_accessor` | alias: `attr` |
| `#ancestors` | |
| `#inspect` | defined on the Module side |

---

## Integer

`prelude/integer.rs`

| Method | Notes |
|---|---|
| `#[]` | bit reference |
| `#-@` | unary minus |
| `#+` | mixed arithmetic with Float |
| `#-` | mixed arithmetic with Float |
| `#**` | mixed arithmetic with Float |
| `#%` | |
| `#&` | bitwise AND |
| `#\|` | bitwise OR |
| `#^` | bitwise XOR |
| `#~` | bitwise NOT |
| `#<<` | left shift |
| `#>>` | right shift |
| `#abs` | |
| `#to_i` | |
| `#to_f` | |
| `#chr` | |
| `#times` | takes a block |
| `#inspect` | alias: `to_s` |
| `#clamp` | |

---

## Float

`prelude/float.rs`

| Method | Notes |
|---|---|
| `#to_i` | |
| `#to_f` | |
| `#+` | mixed arithmetic with Integer |
| `#-` | mixed arithmetic with Integer |
| `#*` | mixed arithmetic with Integer |
| `#/` | mixed arithmetic with Integer |
| `#+@` | unary plus |
| `#-@` | unary minus |
| `#**` | mixed arithmetic with Integer |
| `#abs` | |
| `#inspect` | alias: `to_s` |
| `#clamp` | |

---

## NilClass

`prelude/nilclass.rs`

| Method | Notes |
|---|---|
| `#to_s` | returns `""` |
| `#inspect` | returns `"nil"` |
| `#nil?` | returns `true` |

---

## TrueClass

`prelude/trueclass.rs`

| Method | Notes |
|---|---|
| `#to_s` | alias: `inspect` |
| `#&` | |
| `#\|` | |
| `#^` | |

---

## FalseClass

`prelude/falseclass.rs`

| Method | Notes |
|---|---|
| `#to_s` | alias: `inspect` |
| `#&` | |
| `#\|` | |
| `#^` | |

---

## Symbol

`prelude/symbol.rs`

| Method | Notes |
|---|---|
| `#to_s` | |
| `#inspect` | `:sym` format |
| `#to_proc` | converts symbol to a proc that calls the method |

---

## Proc

`prelude/proc.rs`

| Method | Notes |
|---|---|
| `.new` | class method |
| `#call` | |

---

## String

`prelude/string.rs`

| Method | Notes |
|---|---|
| `.new` | class method |
| `#+` | string concatenation |
| `#*` | repetition |
| `#<<` | destructive append |
| `#[]` | alias: `slice` |
| `#[]=` | cf. `slice!` |
| `#b` | returns a binary (byte) string |
| `#clear` | |
| `#chomp` | |
| `#chomp!` | |
| `#dup` | |
| `#empty?` | |
| `#getbyte` | |
| `#setbyte` | |
| `#index` | |
| `#ord` | |
| `#slice` | |
| `#slice!` | |
| `#split` | |
| `#lstrip` | |
| `#lstrip!` | |
| `#rstrip` | |
| `#rstrip!` | |
| `#strip` | |
| `#strip!` | |
| `#to_sym` | alias: `intern` |
| `#start_with?` | |
| `#end_with?` | |
| `#include?` | |
| `#bytes` | |
| `#chars` | |
| `#upcase` | |
| `#upcase!` | |
| `#downcase` | |
| `#downcase!` | |
| `#to_i` | |
| `#to_f` | |
| `#unpack` | pack format: `Q q L l I i S s C c` |
| `#size` | alias: `bytesize`, `length` |
| `#inspect` | |
| `#to_s` | |
| `#=~` | added by `[feature: mruby-regexp]` |
| `#!~` | added by `[feature: mruby-regexp]` |

---

## Enumerable (module)

`prelude/enumerable.rs`  
Included in Array, Hash, and Range.

| Method | Notes |
|---|---|
| `#map` | |
| `#find` | |
| `#select` | |
| `#all?` | |
| `#any?` | |
| `#delete_if` | |
| `#each_with_index` | |
| `#sort` | |
| `#sort_by` | |
| `#max` | |
| `#min` | |
| `#minmax` | |
| `#compact` | |
| `#count` | |
| `#to_a` | |
| `#uniq` | |
| `#reduce` | |
| `#sum` | |

---

## Array

`prelude/array.rs`  
Includes Enumerable.

| Method | Notes |
|---|---|
| `.new` | class method |
| `#+` | returns a new array containing elements from both arrays |
| `#push` | alias: `<<` |
| `#[]` | alias: `at` |
| `#[]=` | |
| `#clear` | |
| `#delete_at` | |
| `#each` | |
| `#empty?` | |
| `#size` | alias: `length` |
| `#include?` | |
| `#&` | set intersection |
| `#\|` | set union |
| `#first` | |
| `#last` | |
| `#pop` | |
| `#shift` | |
| `#unshift` | |
| `#dup` | |
| `#uniq!` | |
| `#map!` | |
| `#select!` | |
| `#reject!` | |
| `#sort!` | |
| `#sort_by!` | |
| `#pack` | format: `Q q L l I i S s C c` |
| `#inspect` | alias: `to_s` |
| `#join` | |
| `#flatten` | returns a new flattened array (recursive) |
| `#flatten!` | flattens self in place (recursive), returns self or nil |

---

## Hash

`prelude/hash.rs`  
Includes Enumerable.

| Method | Notes |
|---|---|
| `.new` | class method |
| `#[]` | |
| `#[]=` | |
| `#clear` | |
| `#dup` | |
| `#delete` | |
| `#empty?` | |
| `#has_key?` | |
| `#has_value?` | |
| `#key` | reverse lookup: value → key |
| `#keys` | |
| `#each` | block receives key and value |
| `#size` | alias: `length`, `count` |
| `#merge` | |
| `#merge!` | |
| `#to_h` | |
| `#values` | |
| `#inspect` | alias: `to_s` |
| `#flatten` | returns an array of [key1, value1, key2, value2, ...] |

---

## Range

`prelude/range.rs`  
Includes Enumerable. Integer ranges only.

| Method | Notes |
|---|---|
| `#include?` | supports Integer and Float arguments |
| `#each` | Integer ranges only |

---

## SharedMemory (mruby/edge specific)

`prelude/shared_memory.rs`  
A class for zero-copy sharing with WASM linear memory.

| Method | Notes |
|---|---|
| `.new` | takes a size in bytes |
| `#to_s` | |
| `#offset_in_memory` | alias: `to_i` — returns the memory offset (address) |
| `#[]` | range / index access |
| `#[]=` | |
| `#replace` | |
| `#read_by_size` | |

---

## Random `[feature: mruby-random]`

`prelude/rand.rs`  
Uses the XorShift PRNG.

| Method | Notes |
|---|---|
| `.new` | seed is optional |
| `.rand` | class method |
| `.srand` | class method |
| `#rand` | instance method |
| `#seed` | returns the current seed |

Added to Kernel (Object):

| Method | Notes |
|---|---|
| `#rand` | uses the global default RNG |

---

## Regexp `[feature: mruby-regexp]`

`prelude/regexp.rs`  
Uses the Rust `regex` crate.

| Method | Notes |
|---|---|
| `.new` | alias: `.compile` |
| `#=~` | returns match position or `nil` |
| `#!~` | |
| `#match` | returns a MatchData object |
| `#inspect` | |

### MatchData `[feature: mruby-regexp]`

| Method | Notes |
|---|---|
| `#[]` | capture group reference |

---

## Notes

- Some arithmetic operators (`*`, `/`) for Integer are not defined as instance methods in this prelude; they are handled directly by the VM bytecode interpreter (`eval.rs`).
- Comparison operators (`<`, `<=`, `>`, `>=`) are similarly handled on the VM side.
- `String#=~` and `#!~` are only added when `[feature: mruby-regexp]` is enabled.