Class: Buffer::Array
- Includes:
- Enumerable, Native::Wrapper
- Defined in:
- opal/stdlib/buffer/array.rb
Instance Attribute Summary collapse
-
#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
- #bits ⇒ Object
- #bytesize ⇒ Object
- #each ⇒ Object
-
#initialize(buffer, bits = nil, type = nil) ⇒ Array
constructor
A new instance of Array.
- #length ⇒ Object (also: #size)
- #merge!(other, offset = undefined) ⇒ Object
Methods included from Enumerable
Methods included from Native::Wrapper
Constructor Details
#initialize(buffer, bits = nil, type = nil) ⇒ Array
Returns a new instance of Array.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'opal/stdlib/buffer/array.rb', line 13 def initialize(buffer, bits = nil, type = nil) if Native == buffer super(buffer) else %x{ var klass = #{Array.for(bits, type)}; #{super(`new klass(#{buffer.to_n})`)} } end @buffer = buffer @type = type end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
11 12 13 |
# File 'opal/stdlib/buffer/array.rb', line 11 def buffer @buffer end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'opal/stdlib/buffer/array.rb', line 11 def type @type end |
Class Method Details
Instance Method Details
#[](index, offset = nil) ⇒ Object
32 33 34 |
# File 'opal/stdlib/buffer/array.rb', line 32 def [](index, offset = nil) offset ? `#{@native}.subarray(index, offset)` : `#{@native}[index]` end |
#[]=(index, value) ⇒ Object
36 37 38 |
# File 'opal/stdlib/buffer/array.rb', line 36 def []=(index, value) `#{@native}[index] = value` end |
#bits ⇒ Object
28 29 30 |
# File 'opal/stdlib/buffer/array.rb', line 28 def bits `#{@native}.BYTES_PER_ELEMENT * 8` end |
#bytesize ⇒ Object
40 41 42 |
# File 'opal/stdlib/buffer/array.rb', line 40 def bytesize `#{@native}.byteLength` end |
#each ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'opal/stdlib/buffer/array.rb', line 44 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
56 57 58 |
# File 'opal/stdlib/buffer/array.rb', line 56 def length `#{@native}.length` end |
#merge!(other, offset = undefined) ⇒ Object
60 61 62 |
# File 'opal/stdlib/buffer/array.rb', line 60 def merge!(other, offset = undefined) `#{@native}.set(#{other.to_n}, offset)` end |