(can you tell I’m learning Ruby today? :))
I want to determine if the multidimensional array I’m working with is a ‘rectangle’–i.e., the rows are the same size. Here’s what I’m doing, which works but feels clunky.
if @myArray[0].size != @myArray[0..@myArray.size].size raise 'This array is not a rectangle.' end
Basically, I’m checking if the first array’s size if equal to all the other array’s size. Somehow, it seems this isn’t ‘ruby’ enough, you know? Anyone have any more elegant solutions?
Try:
See http://www.ruby-doc.org/core/classes/Array.html (the [] operator) and http://www.ruby-doc.org/core/classes/Enumerable.html (the any? method)