ruby on rails - Enumerable select to set attribute and return object -


i need iterate on array, set attribute, , return modified objects.

obviously, map can used so:

items.map |item|    item.foo = bar    item end 

but seems bulky such simple operation.

using select more simple.

items.select { |item| item.foo = bar } 

however, i've used select test condition. in scenario, condition not being tested during iteration, still returning true upon setting attribute.

is acceptable way use select or hack?


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -