3 ms·
This is an aside, but don't use the ruby "to_proc" approach that listed in the article. i.e: result = collection.select(&:condition?) The "&:proc" methods a
by jwilliams 14y ago
This is an aside, but don't use the ruby "to_proc" approach that listed in the article. i.e:
result = collection.select(&:condition?)
The "&:proc" methods are (very, very likely) slower and they also "leak".
When I say "leak", the VM doesn't Garbage Collect the parameters of the proc until it is used again. Most of the time this is fine, but when it's not, you're wasting considerable amounts of memory. This is known and is considered within the spec.
I know they are semantically equivalent, but the MRI is doing something weird internally. (ps. Learnt this the hard way).