On 06.09.2008 20:17, Erwin wrote:
>      works =  Array.new
>      session[:cart_works].each_pair {|key, value| works << key if
> value == user_id}
> 
> how to initialize the works array in the bloc ?

You cannot do it inside the block because then it is not know after the 
block because of how the scoping works:

$ ruby -e '[1].each { w = 10 }; p w'
-e:1: undefined local variable or method `w' for main:Object (NameError)

You can do

works = session[:cart_works].inject [] do |w,(k,v)|
   w << k if v == user_id
   w
end

works = session[:cart_works].select {|k,v| v == user_id}.map {|k,v| k}

Kind regards

	robert