From: Piyush Ranjan Date: 2008-09-07T04:01:10+09:00 Subject: Re: any way to write it in one line ? ------=_Part_97588_28455353.1220728030919 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline works =3D Array.new; session[:cart_works].each_pair {|key, value| works <= < key if value =3D=3D user_id} there! fits in one line :P :P On Sun, Sep 7, 2008 at 12:06 AM, Jes=FAs Gabriel y Gal=E1n < jgabrielygalan@gmail.com> wrote: > > > > On Sat, Sep 6, 2008 at 7:14 PM, Erwin wrote: > > > >> works =3D Array.new > >> session[:cart_works].each_pair {|key, value| works << key if > >> value =3D=3D 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 =3D Array.new unle= ss > > works > > works << key if value =3D=3D 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 =3D Array.new unless arr; arr << > k if v=3D=3D3} > =3D> {:c=3D>3, :a=3D>3, :b=3D>5} > irb(main):008:0> arr > NameError: undefined local variable or method `arr' for main:Object > from (irb):8 > > Jesus. > > ------=_Part_97588_28455353.1220728030919--