Class: Y::Lib0::TypedArray
- Inherits:
-
Array
- Object
- Array
- Y::Lib0::TypedArray
- Defined in:
- lib/y/lib0/typed_array.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ TypedArray
constructor
A new instance of TypedArray.
- #replace_with(array, offset = 0) ⇒ Object
Constructor Details
#initialize ⇒ TypedArray #initialize(size) ⇒ TypedArray #initialize(typed_array) ⇒ TypedArray #initialize(buffer) ⇒ TypedArray #initialize(buffer, offset) ⇒ TypedArray #initialize(buffer, offset, size) ⇒ TypedArray
Returns a new instance of TypedArray.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/y/lib0/typed_array.rb', line 20 def initialize(*args) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity if args.empty? super() elsif args.size == 1 && args.first.is_a?(Numeric) super(args.first, 0) elsif args.size == 1 && args.first.is_a?(TypedArray) super(args.first) elsif args.size == 1 && args.first.is_a?(Enumerable) super(args.first.to_a) elsif args.size == 2 && args.first.is_a?(Enumerable) && args.last.is_a?(Numeric) super(args.first.to_a[(args.last)..]) elsif args.size == 3 && args.first.is_a?(Enumerable) && args[1].is_a?(Numeric) && args.last.is_a?(Numeric) super(args.first.to_a[args[1], args.last]) else raise "invalid arguments: [#{args.join(", ")}" end end |
Instance Method Details
#replace_with(array, offset = 0) ⇒ Object
38 39 40 41 42 |
# File 'lib/y/lib0/typed_array.rb', line 38 def replace_with(array, offset = 0) array.each_with_index do |element, index| self[offset + index] = element end end |