Class/Module Index [+]

Quicksearch

TypedArray

Provides TypedArray functionality to a subclass of Array when extended in the class's definiton


Namespace TypedArray

Public Class Methods

extended( mod ) click to toggle source

Hook the extension process in order to include the necessary functions and do some basic sanity checks.

# File lib/typed-array.rb, line 11
def self.extended( mod )
  unless mod <= Array
    raise UnexpectedTypeException.new( [Array], mod.class )
  end
  mod.module_exec(self::Functions) do |functions_module|
    include functions_module
  end
end

Public Instance Methods

inherited( subclass ) click to toggle source

when a class inherits from this one, make sure that it also inherits the types that are being enforced

# File lib/typed-array.rb, line 22
def inherited( subclass )
  self._subclasses << subclass
  subclass.restricted_types *restricted_types
end
restricted_type(*types) click to toggle source
Alias for: restricted_types
restricted_types(*types) click to toggle source

A getter/setter for types to add. If no arguments are passed, it simply returns the current array of accepted types.

# File lib/typed-array.rb, line 29
def restricted_types(*types)
  @_restricted_types ||= []
  types.each do |type|
    raise UnexpectedTypeException.new([Class],type.class) unless type.is_a? Class
    @_restricted_types << type unless @_restricted_types.include? type
    _subclasses.each do |subclass|
      subclass.restricted_types type
    end
  end
  @_restricted_types
end
Also aliased as: restricted_type

Protected Instance Methods

_subclasses() click to toggle source

a store of subclasses

# File lib/typed-array.rb, line 59
def _subclasses
  @_subclasses ||= []
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.