explain the arrays in rubyruby arrays are dynamic


Explain the Arrays in Ruby

Ruby arrays are dynamic arrays which expand automatically whenever a value is stored in a location beyond current end of the array. To the programmer, it's as if arrays are unbounded and as many locations as are needed are available. Locations not assigned a value in an expanded array are initialized to nil by default. Ruby also has an interesting indexing mechanism for arrays. Array indices begin at 0 so, for instance, a[13] is the value in the 14th position of the array. Negative numbers are indices of elements counting from current end of the array, so a[-1] is the last element, a[-2] is the second to last element, and so forth. Array references which use an out-of-bound index return nil. These features combine to make it difficult to write an array reference which causes an indexing error. This is apparently a great convenience to the programmer however actually it's not since it makes it so hard to find bugs: many unintended and erroneous array references are legal.

 

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: explain the arrays in rubyruby arrays are dynamic
Reference No:- TGS0356376

Expected delivery within 24 Hours