From: Robert Klemme Date: 2011-07-14T16:56:07+09:00 Subject: Re: [ANN] summaryse 1.1.0 Released On Tue, Jul 12, 2011 at 9:58 PM, Bernard Lambeau wrote: > summaryse version 1.1.0 has been released! > > sudo gem summaryse > > After birthday yesterday, I already reached a second milestone. A lot > of useful features added for fun and profit! Examples are given in the > changelog exerpt below. > > Array#summaryse > > * > * > > Summarize arrays with full power. As a side effect, this gem allows merging > multiple YAML configuration files with power, without sacrifying > simplicity... > > Changes: > > # 1.1.0 / 2011.07.12 > >  * Added a way to register user-defined aggregation functions: > >        Summaryse.register(:comma_join) do |ary| >          ary.join(', ') >        end >        [1, 4, 12, 7].summaryse(:comma_join) >        # => "1, 4, 12, 7" Personally I'd rather directly use #join - it's short as well and much clearer what is happening - especially if #register and #summaryse calls are in separate locations. >  * Added the ability to specify aggregations on hash keys that are not used > at >    all. In this case, the aggregator is called on an empty array. > >        [ >          { :size => 12 }, >          { :size => 17 } >        ].summaryse(:size => :max, :hobbies => lambda{|a| a}) >        # => {:size => 17, :hobbies => []} I am not sure I understand what this is good for. Can you provide a bit more insight? >  * Added the ability to use objects responding to to_summaryse as > aggregator >    functions: > >        class Foo >          def to_summaryse; :sum; end >        end >        [1, 2, 3].summaryse(Foo.new) >        # => 6 Why would I want to do that? Wouldn't it be much shorter to just use the constant? >  * Added the ability to explicitly bypass Hash entries as the result of a >    computation, by returning Summaryse::BYPASS > >        [ >          { :hobbies => [:ruby],  :size => 12 }, >          { :hobbies => [:music], :size => 17 } >        ].summaryse(:size => :max, :hobbies => lambda{|a| > Summaryse::BYPASS}) >        # => {:size => 17} Hm... Generally I would rather implement those directly. The reason is simply that this will reduce component dependencies of my applications by one. When weighting using an external component (e.g. a gem) vs. doing it internally the benefit must be higher than the cost for me. YMMV though. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/