-
Enumerables–A Cleaner Way to Iterate!!! [Ruby Programming Language Notes]
ENUMERABLES Enumerables–a cleaner way to iterate. Enumerable Methods–a way to quickly iterate thru an array or string array. array .each The ‘.each’ method takes in a {block-of-code} instead of (parameters). ‘.each’ passes on just the element. {block-of-code}–uses curly brackets{} to represent it. .each_with_index The ‘.each_with_index’ passes on the element, with the index, to the block of code. string .each_char .each_char.with_index Range enumerable–allows us to control where we start iterating & where we stop. (start..end).each iterate from start to end (inclusive!) (start…end).each iterate from start to end (excluding end!) A range can also be used on letters & other patterns, not just numbers!) Array Syntax for it: months = [ “Jan”,…