I don’t think there is a way to do this. Exists with instance or class variables, but rarely happens with local variables.
In your case, you really should have the data in a hash. Also, logic like this really doesn't belong to erb. You want something like:
working_hour_sets = %w[mon tue wed thu fri sat sun].inject({}) do |hash, day|
hash[day]=0;
hash
end
# puts working_hour_sets #=> {"wed"=>0, "sun"=>0, "thu"=>0, "mon"=>0, "tue"=>0, "sat"=>0, "fri"=>0}
working_hour_sets.each do |day, value|
working_hour_sets[day] = 1 if condition?
end
source
share