In Ruby is it possible to reference the array object being generated with a .map function from within that .map code block?
A very simple example would be if you were trying to only add unique elements to the returned array and wanted to check to see if that element already existed, which might look like:
array.map{ |v| v unless (reference to array being created by this map function).include?(v) }
I know that functionally this code is unnecessary because you could simply use a .uniq method on the array or push values into a separate array and check if that array already includes the value, I'm just wondering if it's possible conceptually as I've encountered a few times where such a reference would be useful. Thanks.
reduce,select,reject,each_with_objectare more ideal for this kind of problem, if you show a use case it would be easier to identify which to you