0

I'm tying to show active user names using this code:

<%= User.count(:activeuser, :distinct => true, :group => 'name') %> 

currently it showing this ugly result:

{"Webster"=>0, "Wilfrid"=>0, "Winifred"=>0, "Nicolas"=>1, "Cage"=>1} 

how can i make this pretty? like showing only true users Nicolas and Cage

1 Answer 1

1

If you want to filter a Hash to include only items that meet particular criteria, use Hash#select:

hsh = {"Webster"=>0, "Wilfrid"=>0, "Winifred"=>0, "Nicolas"=>1, "Cage"=>1} hsh.select {|key, val| val > 0 } # => {"Nicolas"=>1, "Cage"=>1} 

...or, to exclude items, Hash#reject:

hsh.reject {|key, val| val.zero? } # => {"Nicolas"=>1, "Cage"=>1} 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.