arrays - Ruby Select and Reject in one method -


is there built in method combine functions of select (find block equates true) , reject (find block equates false)?

something like

good, bad = list.magic_method { |obj| obj.good? } 

wouldn't hard myself nih , that. :)

looks if enumerable.partition after.

= enumerable.partition  (from ruby core) ------------------------------------------------------------------------------   enum.partition {| obj | block }  -> [ true_array, false_array ]   enum.partition                   -> an_enumerator  ------------------------------------------------------------------------------  returns 2 arrays, first containing elements of enum block evaluates true, second containing rest.  if no block given, enumerator returned instead.     (1..6).partition {|i| (i&1).zero?}   #=> [[2, 4, 6], [1, 3, 5]] 

interesting, didn't know there. ri amazing tool...


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -