"itsme213" <itsme213 / hotmail.com> schrieb im Newsbeitrag
news:I7Jrd.100267$jq5.22882 / fe2.texas.rr.com...
> def foo
>     bar [:a, :b, :c]
>     a
>     b
>     c
> end
>
> I would like a, b, and c to be local variables with values 1, 2, 3
> (positions of :a, :b, :c). Is there some implementation of
>     def bar (symbol_list)
>         symbol_list.each_with_index { |s, i|
>             ???
>         }
>     end
> that will do this?

As Mark pointed out, you can't get this to work because of the compile
time decisions Ruby takes.  You can either do this

def bar(*a) 0...a.size end

def foo
  a,b,c = *bar(:a,:b,:c)
  puts a,b,c
end

or this

def bar2(b,*a)
  a.each_with_index {|s,i| eval("#{s}=#{i}",b)}
end

def foo2
  bind = binding
  bar2(bind, :a,:b,:c)
  [:a,:b,:c].each do |sym|
    puts eval(sym.to_s, bind)
  end
end

which is really clumsy.

Kind regards

    robert