Class: FixedSizedHomogeneousArray

Inherits:
HomogeneousArray show all
Defined in:
lib/symphony/symphony.rb

Instance Attribute Summary collapse

Attributes inherited from HomogeneousArray

#klass

Instance Method Summary collapse

Methods inherited from HomogeneousArray

#==, #raise_type_error

Methods inherited from Array

#/, #to_homogeneous

Constructor Details

#initialize(capacity, of_class, *spec) ⇒ FixedSizedHomogeneousArray

Returns a new instance of FixedSizedHomogeneousArray.



84
85
86
87
88
89
# File 'lib/symphony/symphony.rb', line 84

def initialize(capacity, of_class, *spec)
  raise_capacity_error(spec.last.size, capacity) if spec.last.size != capacity
  
  super(of_class, *spec)
  @capacity = capacity
end

Instance Attribute Details

#capacityObject (readonly)

Returns the value of attribute capacity.



82
83
84
# File 'lib/symphony/symphony.rb', line 82

def capacity
  @capacity
end

Instance Method Details

#<<(obj) ⇒ Object



96
97
98
99
# File 'lib/symphony/symphony.rb', line 96

def <<(obj)
  raise_capacity_error(self.size + 1) if self.size + 1 != self.capacity
  super(obj)
end

#[]=(*assign_spec) ⇒ Object



91
92
93
94
# File 'lib/symphony/symphony.rb', line 91

def []=(*assign_spec)
  super(*assign_spec)
  raise_capacity_error(self.size) if self.size != self.capacity
end

#delete(obj) ⇒ Object



106
# File 'lib/symphony/symphony.rb', line 106

def delete(obj); end

#delete_at(index) ⇒ Object



107
# File 'lib/symphony/symphony.rb', line 107

def delete_at(index); end

#replace(array_of_obj) ⇒ Object



101
102
103
104
# File 'lib/symphony/symphony.rb', line 101

def replace(array_of_obj)
  aise_capacity_error(self.size + array_of_obj.size) if self.size + array_of_obj.size != self.capacity
  super(array_of_obj)
end