Piyush Ranjan
9/6/2008 7:01:00 PM
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 <yves_dufour@mac.com> 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 <buddhamagnet@gmail.com>
> 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.
>
>