Module: TypedArray
- Defined in:
- lib/typed-array.rb,
lib/typed-array/functions.rb
Overview
Namespace TypedArray
Defined Under Namespace
Modules: Functions Classes: UnexpectedTypeException
Class Method Summary collapse
-
.extended(mod) ⇒ Object
Hook the extension process in order to include the necessary functions and do some basic sanity checks.
Instance Method Summary collapse
-
#inherited(subclass) ⇒ Object
when a class inherits from this one, make sure that it also inherits the types that are being enforced.
-
#restricted_types(*types) ⇒ Object
(also: #restricted_type)
A getter/setter for types to add.
Class Method Details
.extended(mod) ⇒ Object
Hook the extension process in order to include the necessary functions and do some basic sanity checks.
11 12 13 14 15 16 17 18 |
# 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 |
Instance Method Details
#inherited(subclass) ⇒ Object
when a class inherits from this one, make sure that it also inherits the types that are being enforced
22 23 24 25 |
# File 'lib/typed-array.rb', line 22 def inherited( subclass ) self._subclasses << subclass subclass.restricted_types *restricted_types end |
#restricted_types(*types) ⇒ Object Also known as: restricted_type
A getter/setter for types to add. If no arguments are passed, it simply returns the current array of accepted types.
29 30 31 32 33 34 35 36 37 38 39 |
# 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 |