Class: Buffer

Inherits:
Object
  • Object
show all
Includes:
Native
Defined in:
lib/opal/typed-array/view.rb,
lib/opal/typed-array/array.rb,
lib/opal/typed-array/buffer.rb

Overview

          DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                  Version 2, December 2004

          DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.

++

Defined Under Namespace

Classes: Array, View

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size, bits = 8) ⇒ Buffer

Returns a new instance of Buffer.



25
26
27
# File 'lib/opal/typed-array/buffer.rb', line 25

def initialize (size, bits = 8)
	super(`new ArrayBuffer(size * (bits / 8))`)
end

Class Method Details

.name_for(bits, type) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/opal/typed-array/buffer.rb', line 15

def self.name_for (bits, type)
	"#{case type
		when :unsigned then 'Uint'
		when :signed   then 'Int'
		when :float    then 'Float'
	end}#{bits}"
end

Instance Method Details

#lengthObject Also known as: size



29
30
31
# File 'lib/opal/typed-array/buffer.rb', line 29

def length
	`#@native.byteLength`
end

#to_a(bits = 8, type = :unsigned) ⇒ Object



35
36
37
# File 'lib/opal/typed-array/buffer.rb', line 35

def to_a (bits = 8, type = :unsigned)
	Array.new(self, bits, type)
end

#view(offset = nil, length = nil) ⇒ Object



39
40
41
# File 'lib/opal/typed-array/buffer.rb', line 39

def view (offset = nil, length = nil)
	View.new(self, offset, length)
end