From: William James Date: 2008-09-07T04:14:01+09:00 Subject: Re: any way to write it in one line ? On Sep 6, 1:17 pm, Erwin wrote: > works = Array.new works = [] Instead of name = String.new one says name = "" > session[:cart_works].each_pair {|key, value| works << key if > value == user_id} > > how to initialize the works array in the bloc ? > > thanks for your lights > > erwin h = Hash[ * %w(apple red lemon yellow bananna yellow orange orange) ] ==>{"bananna"=>"yellow", "apple"=>"red", "orange"=>"orange", "lemon"=>"yello w"} a = h.keys.select{|k| 'yellow'==h[k] } ==>["bananna", "lemon"]