Class: TypedArray
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #+(array) ⇒ Object
- #<<(e) ⇒ Object
- #[]=(index, e) ⇒ Object
- #check_array_passed(obj) ⇒ Object
-
#check_type_for_obj(obj) ⇒ Object
:nodoc:.
-
#check_types_for_array(array) ⇒ Object
:nodoc:.
- #compact ⇒ Object
- #compact! ⇒ Object
- #concat(array) ⇒ Object
- #flatten ⇒ Object
- #flatten! ⇒ Object
-
#initialize(type, elements = []) ⇒ TypedArray
constructor
A new instance of TypedArray.
- #old_plus ⇒ Object
- #push(e) ⇒ Object
Constructor Details
#initialize(type, elements = []) ⇒ TypedArray
Returns a new instance of TypedArray.
5 6 7 8 9 10 |
# File 'lib/scruby/typed_array.rb', line 5 def initialize( type, elements = [] ) @type = type.instance_of?(Class) ? type : type.class check_array_passed( elements ) check_types_for_array( elements ) super( elements ) end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/scruby/typed_array.rb', line 3 def type @type end |
Instance Method Details
#+(array) ⇒ Object
13 14 15 |
# File 'lib/scruby/typed_array.rb', line 13 def +( array ) TypedArray.new( @type, self.old_plus( array ) ) end |
#<<(e) ⇒ Object
23 24 25 26 |
# File 'lib/scruby/typed_array.rb', line 23 def <<(e) check_type_for_obj(e) super end |
#[]=(index, e) ⇒ Object
28 29 30 31 |
# File 'lib/scruby/typed_array.rb', line 28 def []=(index, e) check_type_for_obj(e) super end |
#check_array_passed(obj) ⇒ Object
52 53 54 |
# File 'lib/scruby/typed_array.rb', line 52 def check_array_passed(obj) raise TypeError.new( "#{obj} is not Array" ) unless obj.instance_of?(Array) end |
#check_type_for_obj(obj) ⇒ Object
:nodoc:
60 61 62 |
# File 'lib/scruby/typed_array.rb', line 60 def check_type_for_obj( obj ) #:nodoc: raise TypeError.new("#{obj} is not instance of #{@type}") unless obj.instance_of?(@type) end |
#check_types_for_array(array) ⇒ Object
:nodoc:
56 57 58 |
# File 'lib/scruby/typed_array.rb', line 56 def check_types_for_array( array ) #:nodoc: raise TypeError.new("All elements of #{array} should be instance of #{@type}") unless array.reject{ |e| e.instance_of?(@type) }.empty? end |
#compact ⇒ Object
42 43 44 |
# File 'lib/scruby/typed_array.rb', line 42 def compact self end |
#compact! ⇒ Object
49 50 |
# File 'lib/scruby/typed_array.rb', line 49 def compact! end |
#concat(array) ⇒ Object
17 18 19 20 21 |
# File 'lib/scruby/typed_array.rb', line 17 def concat( array ) check_array_passed( array ) check_types_for_array( array ) super end |
#flatten ⇒ Object
38 39 40 |
# File 'lib/scruby/typed_array.rb', line 38 def flatten self end |
#flatten! ⇒ Object
46 47 |
# File 'lib/scruby/typed_array.rb', line 46 def flatten! end |
#old_plus ⇒ Object
12 |
# File 'lib/scruby/typed_array.rb', line 12 alias :old_plus :+ |
#push(e) ⇒ Object
33 34 35 36 |
# File 'lib/scruby/typed_array.rb', line 33 def push(e) check_type_for_obj(e) super end |