Class: Buffer::Array
- Inherits:
-
Object
- Object
- Buffer::Array
- Includes:
- Enumerable, Native
- Defined in:
- lib/opal/typed-array/array.rb
Instance Attribute Summary collapse
-
#bits ⇒ Object
readonly
Returns the value of attribute bits.
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #[](index, offset = nil) ⇒ Object
- #[]=(index, value) ⇒ Object
- #bytesize ⇒ Object
- #each ⇒ Object
-
#initialize(buffer, bits, type) ⇒ Array
constructor
A new instance of Array.
- #length ⇒ Object (also: #size)
- #merge!(other, offset = undefined) ⇒ Object
Constructor Details
#initialize(buffer, bits, type) ⇒ Array
Returns a new instance of Array.
23 24 25 26 27 28 29 30 31 |
# File 'lib/opal/typed-array/array.rb', line 23 def initialize (buffer, bits, type) klass = Array.for(bits, type) super(`new klass(#{buffer.to_native})`) @buffer = buffer @bits = `#@native.BYTES_PER_ELEMENT * 8` @type = type end |
Instance Attribute Details
#bits ⇒ Object (readonly)
Returns the value of attribute bits.
21 22 23 |
# File 'lib/opal/typed-array/array.rb', line 21 def bits @bits end |
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
21 22 23 |
# File 'lib/opal/typed-array/array.rb', line 21 def buffer @buffer end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
21 22 23 |
# File 'lib/opal/typed-array/array.rb', line 21 def type @type end |
Class Method Details
Instance Method Details
#[](index, offset = nil) ⇒ Object
33 34 35 |
# File 'lib/opal/typed-array/array.rb', line 33 def [] (index, offset=nil) offset ? `#@native.subarray(index, offset)` : `#@native[index]` end |
#[]=(index, value) ⇒ Object
37 38 39 |
# File 'lib/opal/typed-array/array.rb', line 37 def []= (index, value) `#@native[index] = value` end |
#bytesize ⇒ Object
41 42 43 |
# File 'lib/opal/typed-array/array.rb', line 41 def bytesize `#@native.byteLength` end |
#each ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/opal/typed-array/array.rb', line 45 def each return enum_for :each unless block_given? %x{ for (var i = 0, length = #@native.length; i < length; i++) { #{yield `#@native[i]`} } } self end |
#length ⇒ Object Also known as: size
57 58 59 |
# File 'lib/opal/typed-array/array.rb', line 57 def length `#@native.length` end |
#merge!(other, offset = undefined) ⇒ Object
61 62 63 |
# File 'lib/opal/typed-array/array.rb', line 61 def merge! (other, offset = undefined) `#@native.set(#{other.to_native}, offset)` end |