Class: WasmDRb::ArrayBuffer
- Inherits:
-
Object
- Object
- WasmDRb::ArrayBuffer
- Defined in:
- lib/wasm_drb/array_buffer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #buffer ⇒ Object
-
#initialize(data) ⇒ ArrayBuffer
constructor
A new instance of ArrayBuffer.
- #length ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data) ⇒ ArrayBuffer
Returns a new instance of ArrayBuffer.
5 6 7 |
# File 'lib/wasm_drb/array_buffer.rb', line 5 def initialize(data) @js_array = JS.global[:Uint8Array].new(data) end |
Class Method Details
.from_array(arr) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/wasm_drb/array_buffer.rb', line 9 def self.from_array(arr) @js_array = JS.global[:Uint8Array].new(arr.length) arr.each_with_index do |i, v| @js_array[i] = v end end |
Instance Method Details
#buffer ⇒ Object
16 17 18 |
# File 'lib/wasm_drb/array_buffer.rb', line 16 def buffer @js_array[:buffer] end |
#length ⇒ Object
20 21 22 |
# File 'lib/wasm_drb/array_buffer.rb', line 20 def length @js_array[:length] end |
#to_s ⇒ Object
24 25 26 27 28 |
# File 'lib/wasm_drb/array_buffer.rb', line 24 def to_s @js_array.to_a.map do |d| d.to_i.chr end.join end |