What you want is map, not each (the ruby-doc is always your friend):
def self.show_pending_users
self.find(:all, :conditions => "pending_role is not null").map {|x|
"#{x.login}" }
end
-
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en)
On Fri, Feb 27, 2009 at 3:30 PM, Sergio Ruiz
<[email protected]> wrote:
>
> i am having a problem with a current piece of code, and it seems like
> the result for each on an array might be the culprit.
>
> according to everything i have seen before, this should work:
>
> a = [ "a", "b", "c" ]
> a.each {|x| print x, " -- " }
>
> should produce:
>
> a -- b -- c --
>
>
> but i am getting:
>
>>> a = [ "a", "b", "c" ]
> => ["a", "b", "c"]
>>> a.each {|x| print x, " -- " }
> a -- b -- c -- => ["a", "b", "c"]
>
> does anyone know where the => ["a", "b", "c"] is coming from?
>
> specifically, i am trying to run:
>
> def self.show_pending_users
> self.find(:all, :conditions => "pending_role is not null").each {
> |x| "#{x.login}" }
> end
>
> where i expect to get a an array of x.login back.. but i am getting back
> an array of all the objects ...
>
> any ideas?
>
> thanks!
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: 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/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---