Forum: Ruby on Rails variable using problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
engamocap (Guest)
on 2009-03-16 11:19
(Received via mailing list)
I have an array A = ['XXX','YYY','ZZZ','RRR','WWW']
For each element of array I must execute a query on my database.
I don't want write this code:

A.each {
  |elem|
  case elem
  when 'XXX' do Model.find(:all,:select => 'COD',:group =>
'COD',:include => :table).map{|el| el.table.XXX}.sort
   .
   .
   .
  end
}

I'd like this:

A.each {
  |elem|
  Model.find(:all,:select => 'COD',:group => 'COD',:include
=> :table).map{|el| el.table.elem}.sort
}

But there's a problem in this code. Can you help me? Can I write that?
Thank you very much
Frederick C. (Guest)
on 2009-03-16 13:18
(Received via mailing list)
On Mar 16, 9:18 am, engamocap <removed_email_address@domain.invalid> wrote:

> I'd like this:
>
> A.each {
>   |elem|
>   Model.find(:all,:select => 'COD',:group => 'COD',:include
> => :table).map{|el| el.table.elem}.sort
>
> }

For a given attribute, some_record['foo'] gets you the attribute
value. You might also be interested in the send method.

Fred
This topic is locked and can not be replied to.