[Nitro] Help creating a ObjectGraph adapter for RubyAMF

aaron smith beingthexemplarylists at gmail.com
Thu May 24 08:55:35 EDT 2007


On 5/24/07, Jonathan Buch <john at oxyliquit.de> wrote:
> Hi,
>
> > Is there an easier way of doing this:
> > result.inject([]) do |array,some_model|
> >   array << column_names.inject({}) do |hash,col|
> >     hash[col] = some_model.send(col)
> >     hash
> >   end
> > end
>
> > Just seems like a lot of work. Also If I do have to do it that way,
> > where does the some_model variable come from?
>
> Ah, no, of course you don't.  :)  Use any Ruby means of iterating
> over 2 lists (result which has Og objects, column_names which has
> symbols which lead to methods on the models).
>
> I get from your answer, that you're not yet fully comfortable with
> Ruby as of yet.  Read up the standard documentation for `.inject`.
> In fact .inject shouldn't really be used, as it's slow and can
> lead to misunderstandings.  It just flows from my fingers.  :P
>
> rows = []
> result.each do |some_model|
>    row = []
>    column_names.each do |col|
>      row << some_model.send(col)
>    end
>    rows << row
> end
>
> This is probably more readable to you.  Your AR part does the same
> in a slightly uglier way (.upto(.length) is unnecessary here).
>
> Hope that helps,
>
> Jo
>
> --
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
>

Yeah that helps. I'm pretty comfortable with Ruby actually. I just
knew that using inject is slow. At least slower than results.each.

thanks


More information about the Nitro-general mailing list