To modify array itself use the #map!
, instead of #each
method of Array
. Because the #each
method is used only for value enumerations for Array
, or other classes that include Enumerable
module. Therefore, do as follows:
array.map! { |c| c=c*y**z-1 ; z=z+1 ; c }