josefK wrote: > I encountered this added method to Array (I don't recall > the author - sorry ,) > It converts an Array to a Hash by providing a block to compute the > values given the array elements as keys: > > class Array > def to_h(&block) > Hash[*self.collect{|v| [v,block.call(v)]}.flatten] > end > end > "*" is the "splat" operator when used as a prefix. It takes the following array, and turns into a list of parameters. Without it the argument to Hash[] becomes a single Array, while it expects a list of keys and values. And yes, it does generalize. Try p [1,2,3] p *[1,2,3] in irb to get a better idea of the result. The first prints a single array, the second prints _three separate values_ Vidar