On Thu, Sep 8, 2011 at 10:32 PM, Marc Heiler <shevegen / linuxmail.org> wrote:

> > This is almost certainly the wrong design, as local variables
> > aren't really supposed to be used in this way.
>
> It does not matter how they are "supposed" to be used.
>
> Ruby does not impose it on him.
>
> eval() is a perfectly legit way to solve the problem description he has
> given.
>
> There is no "evil user input" at all.
>
> eval() works and can be used without thinking that it is the wrong
> choice for the given problem.
>
>
It is the wrong choice, not because of security risks, but because it means
you are using your binding as a hash, instead of using a hash as a hash
(though in this case, an array is probably the better choice).


For OP, here is an example of what it might look like


# fyi, Rubyists usually try to pick more meaningful names
# in this case, ts represents the plural of t :)
ts = [ ...init code... ]


# a direct mapping of your original idea
(0..12).each do |i|
  t = ts[i]
  puts t.showURL # also, convention in Ruby is snake_case not cameCase
end


# probably what you really want
ts.each { |t| puts t.showURL }