hash.update is an alias for hash.merge! which is pretty much what I
was doing originally :)

I guess we all have our little quirks, just like perl ruby lets you do
the same thing several ways,

Thanks for all your help guys! Sequel is now working pretty well for
me, although the updating all my scripts to remove the block format
was a pain, but now they all run under jruby, so it is good.


On Jun 30, 2:46 pm, "Aman Gupta" <[EMAIL PROTECTED]> wrote:
> I usually use Hash#update, which returns the hash:
>   [1,2,3].inject(Hash.new){|hash, number| hash.update number => number*2 }
>
>   Aman
>
> On Mon, Jun 30, 2008 at 2:24 PM, Jim Morris <[EMAIL PROTECTED]> wrote:
>
> > Point taken, I've been bitten by that inject typo many times, and
> > still make the same mistake!!
> > Maybe I'll remove inject from my repertoire ;)
>
> > On Jun 30, 1:59 pm, Jeremy Evans <[EMAIL PROTECTED]> wrote:
> > > On Jun 30, 12:28 pm, Jim Morris <[EMAIL PROTECTED]> wrote:
>
> > > > Hmm that looks cleaner but gives me an error...
>
> > > > I left out the indexing for simplicity...
>
> > > > v= 123
> > > > periods= [:day, :week, :month, :year, :alltime]
> > > > DB[:stats].update_sql(periods.inject({}){|h, p| h[p] = p + v})
>
> > > > => NoMethodError: undefined method `[]=' for
> > > > #<Sequel::SQL::NumericExpression:0xb7b289c0>
>
> > > I forgot to have the block return the new hash:
>
> > >   ds.update_sql(periods.inject({}){|h, p| h[p|idx] = (p|idx) + v; h})
>
> > > I tend to avoid using inject in such a case anyway, as I find the
> > > following easier to read:
>
> > >   h = {}
> > >   periods.each{|p| h[p|idx] = (p|idx) + v}
> > >   ds.update_sql(h)
>
> > > Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to