Class/Module Index [+]

Quicksearch

TypedArray::Functions

The functions that get included into TypedArray

Public Class Methods

new(*args, &block) click to toggle source

Validates outcome. See Array#initialize

# File lib/typed-array/functions.rb, line 9
def initialize *args, &block
  ary = Array.new *args, &block
  self.replace ary
end

Public Instance Methods

&(ary) click to toggle source

Validates outcome. See Array#&

# File lib/typed-array/functions.rb, line 21
def & ary
  self.class.new super
end
*(int) click to toggle source

Validates outcome. See Array#*

# File lib/typed-array/functions.rb, line 26
def * int
  self.class.new super
end
+(ary) click to toggle source

Validates outcome. See Array#+

# File lib/typed-array/functions.rb, line 31
def + ary
  self.class.new super
end
<<(item) click to toggle source

Validates outcome. See Array#<<

# File lib/typed-array/functions.rb, line 36
def << item
  _ensure_item_is_allowed item
  super
end
[](idx) click to toggle source

Validates outcome. See Array#[]

# File lib/typed-array/functions.rb, line 42
def [] idx
  self.class.new super
end
[]=(idx, item) click to toggle source

Validates outcome. See Array#[]=

# File lib/typed-array/functions.rb, line 52
def []= idx, item
  _ensure_item_is_allowed item
  super
end
concat(other_ary) click to toggle source

Validates outcome. See Array#concat

# File lib/typed-array/functions.rb, line 58
def concat other_ary
  _ensure_all_items_in_array_are_allowed other_ary
  super
end
eql?(other_ary) click to toggle source

Validates outcome. See Array#eql?

# File lib/typed-array/functions.rb, line 64
def eql? other_ary
  _ensure_all_items_in_array_are_allowed other_ary
  super
end
fill(*args, &block) click to toggle source

Validates outcome. See Array#fill

# File lib/typed-array/functions.rb, line 70
def fill *args, &block
  ary = self.to_a
  ary.fill *args, &block
  self.replace ary
end
map!(&block) click to toggle source

Validates outcome. See Array#map!

# File lib/typed-array/functions.rb, line 89
def map! &block
  self.replace( self.map &block )
end
push(*items) click to toggle source

Validates outcome. See Array#push

# File lib/typed-array/functions.rb, line 77
def push *items
  _ensure_all_items_in_array_are_allowed items
  super
end
replace(other_ary) click to toggle source

Validates outcome. See Array#replace

# File lib/typed-array/functions.rb, line 15
def replace other_ary
  _ensure_all_items_in_array_are_allowed other_ary
  super
end
slice(*args) click to toggle source

Validates outcome. See Array#slice

# File lib/typed-array/functions.rb, line 47
def slice *args
  self.class.new super
end
unshift(*items) click to toggle source

Validates outcome. See Array#unshift

# File lib/typed-array/functions.rb, line 83
def unshift *items
  _ensure_all_items_in_array_are_allowed items
  super
end

Protected Instance Methods

_ensure_all_items_in_array_are_allowed(ary) click to toggle source

Ensure that all items in the passed Array are allowed

# File lib/typed-array/functions.rb, line 96
def _ensure_all_items_in_array_are_allowed ary
  # If we're getting an instance of self, accept
  return true if ary.is_a? self.class
  _ensure_item_is_allowed( ary, [Array] )
  ary.each do |item|
    _ensure_item_is_allowed(item)
  end
end
_ensure_item_is_allowed(item, expected=nil) click to toggle source

Ensure that the specific item passed is allowed

# File lib/typed-array/functions.rb, line 106
def _ensure_item_is_allowed item, expected=nil
  return true if item.nil? #allow nil entries
  expected = self.class.restricted_types if expected.nil?
  expected.each do |allowed|
    return true if item.class <= allowed
  end
  raise TypedArray::UnexpectedTypeException.new expected, item.class
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.