Robert Klemme <bob.news / gmx.net> wrote: > "Martin DeMello" <martindemello / yahoo.com> schrieb im Newsbeitrag >> Tangentially, is the following code safe: >> >> def initialize(*factors) >> @factors = factors >> @filters = [] >> @factors.select {|i| i.is_a?(Proc)}.each {|fn| >> (@filters[(fn.arity.abs) -1] ||= []) << fn >> # ( a kludge to get around the fact that {|x|}.arity = -1 ) >> } >> @factors.reject!{|i| i.is_a?(Proc)} >> @dim = @factors.length >> end >> >> assuming the blocks in @factors are guaranteed not to have *d arguments? >> Or is there some insidious corner case I'm missing? > > I'm not sure whether I understand where you're up to. I wonder why you > substract 1 from the abs(arity). To have the array start indexing from 0 :) The bane of array programmers for generations now. The abs() is the kludge I was referring to - it's there solely to take care of the arity=-1 case. > And another tip aside: move the reject! above then @factors.select. Then > you can omit the select and gain a bit performance. :-) Sadly, reject! returns the array, not the rejected elements. I'm trying to separate the array into procs and non-procs (what I ought to do is to use partition, now that it's in 1.8). martin