From: "Jesús Gabriel y Galán" Date: 2008-09-07T03:36:43+09:00 Subject: Re: any way to write it in one line ? > > On Sat, Sep 6, 2008 at 7:14 PM, 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 ? On Sat, Sep 6, 2008 at 8:19 PM, Dave Goodchild wrote: > session[:cat_works].each_pair do |key, value| works = Array.new unless > works > works << key if value == user_id > end I think that in this case works is not visible outside of the block (unless you already had it defined, which kind of defeats the purpose): irb(main):007:0> h.each_pair {|k,v| arr = Array.new unless arr; arr << k if v==3} => {:c=>3, :a=>3, :b=>5} irb(main):008:0> arr NameError: undefined local variable or method `arr' for main:Object from (irb):8 Jesus.