John's answer. Also, the Ruby Hash
API<http://www.ruby-doc.org/core/classes/Hash.html>
.

On Thu, Jun 30, 2011 at 10:10, John Feminella <jo...@bitsbuilder.com> wrote:

> only_new_entries = array_of_hashes.select { |h| h[:status] == "new" }
>
> ~ jf
> --
> John Feminella
> Principal Consultant, BitsBuilder
> LI: http://www.linkedin.com/in/johnxf
> SO: http://stackoverflow.com/users/75170/
>
>
>
> On Thu, Jun 30, 2011 at 09:07, Sebastian <sebastian.go...@googlemail.com>
> wrote:
> > Sorry,
> >
> > yes I have an array of hashes:
> >
> > hash = [{:name => "like", :status => "old"}, {:name => "this", :status
> > => "new"}, {:name => "here", :status => "old"}]
> >
> >
> >
> >
> >
> > On 30 Jun., 14:31, Michael Pavling <pavl...@gmail.com> wrote:
> >> On 30 June 2011 13:27, Sebastian <sebastian.go...@googlemail.com>
> wrote:
> >>
> >> > I have a hash that has a :status key. The value could be 'new' or
> >> > 'old'.
> >>
> >> > Now I want to get only the entries where status is 'new'. I know how
> >> > to do this with an if-clause, but there has to be a better way.
> >>
> >> Do you mean you have an array of hashes? Or a hash where each value is
> >> an object/array?
> >> Can you give an illustration of what your hash looks like, so it's
> >> possible to suggest some solutions.
> >>
> >> Cheers,
> >
> > --
> > 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 rubyonrails-talk@googlegroups.com.
> > To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
> >
> >
>
> --
> 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 rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to