Does anyone know any practical uses for Enumerable#collect? The uses of methods such as select, any?, all?, detect, &c. are all pretty obvious (if esoteric), but I can't see any case in which a coder would need an array of values.
It's usually just for clean coding. You can just use numeric constants in RGSS, that should give about the same effect and pretty much suffice. Other than that I don't know what exactly it could be used for other than, well, enumeration.
I prefer it's synonym
map simply because it conveys what it does much better imo.
For each key map to a value. Return an array of the values. Let's look at a simple example where you have an array of indexes:
indexes = [1,5,4,12]
actors = indexes.map {|i| $game_actors[i]}
Of course the block can be much more complex so you can come into situations where that can help you simplify matters :3
*hugs*
- Zeriab
Ah... I had misunderstood it. I had assumed that it simply returned an array of true or false; it actually returns the value of the block. Millions of times more useful than what I thought it did.
No wonder you couldn't understand its usefulness XD