On Wed, May 14, 2008 at 11:39 AM, Todd Benson <caduceass / gmail.com> wrote:
> On Wed, May 14, 2008 at 10:24 AM, Tim Wolak <tim.wolak / gmail.com> wrote:
>> I posted that code after I fixed an error.  It is getting initialized,
>> after I iterate over the hash its still printing out the numbers that
>> are account numbers for the keys.  I need to get any numbers that are
>> less than 39 and put that in a new hash with the key as SKTY and all
>> values added together into a value for that key.
>>
>> Hope that make more sense of that I'm trying to do.
>>
>> Tim
>
> Let me see.  You want to have a new hash called skty with keys skty
> and sktny?  That's confusing, mostly I think because of your choice of
> variable names.
>
> If you can be sure that all keys are comparable with each other (in
> this case integers), here's very quick and dirty...
>
> class Hash
>  def sum_values
>    values.inject {|s, i| s + i}
>  end

...or maybe better...

class Array
  def sum
    inject {|s, i| s + i}
  end
end

..and then later...

h_new['skty'] = a.values.sum

All this would need to be refactored, of course, to be production-worthy.

Todd