Please help me understand how arrays are translated in rails

I don't understand the '0' portion of the error message but the
problem's not that you don't understand arrays. Try naming your arrays
something else, leaving your method parameters as is. That should get
you going down a productive path.

HTH,
Bill

bill walton wrote:

This will give me:
something like this:

But I get a..

undefined method `[]=' for 0:Fixnum

I don't understand the '0' portion of the error message but the
problem's not that you don't understand arrays. Try naming your arrays
something else, leaving your method parameters as is. That should get
you going down a productive path.

HTH,
Bill

Hi Bill, the issue was that the variables being passed to the class
method from rake were assigned to var=0 so that's why I was getting that
error. I had forgotten to check my rake file and once I went back and
retraced my steps I realized I hadn't passed the type of variable to the
class method (array in this case).

Further,

I have the method working like this now:

def calculate_tsos(model, datavar, teamvar, valvar)
  var = model.compiled_this_week.find(:all, :order => :team_id)
  var.each_with_index do |rows, i|
    teamvar[i] = rows.team.id
    valvar[i] = rows.__send__(datavar)
    puts "#{model} [ Row #{i} | Team ID = #{teamvar[i]} | Team =
#{rows.team.name} | #{datavar} = #{valvar[i]}"
  end
end

As a rake file test, I tried:

to_team_id = []
to_value = []
update_tsos_offense = TsosOffense.new
update_tsos_offense.calculate_tsos(TotalOffense, "ydspgm", to_team_id,
to_value)
puts "From Rake to_team_id = #{to_team_id[1]} and to_value =
#{to_value[1]}"

And receive:

From Rake to_team_id = 2 and to_value = 484.85

.. which is correct so it looks like the values were assigned to the
arrays and that I should be able to use them, once I finish manipulating
them (performing calculations).

But, again, is there a better way to do this? Should I not perform
calculations within the class method on that model? Or, should I keep
things neat and tidy by performing calculations in a ruby file within my
libs directory?

I just want to get better at what I'm doing...

Yes. As Phillip pointed out, "teamvar is an integer... not array."
Sorry I didn't have time, and still don't, to be more help. Reckoned
you'd figure it out with just a hint. At any rate, David has offered
advice and my recommendation is to listen carefully. You can't do
better. When he says "I would tend..." he's saying in the nicest way
possible "that's not how we do it in Ruby." Other than getters in
models, you won't find many examples of 'outbound' parameters in Ruby
methods.

Best regards,
Bill

P.S. When he says "Another thing to think about...", it often means he
already _is_ thinking about it and if prompted with a question like 'how
would that work?' very often says more.

Or a question that demonstrates that you HAVE thought about it. In general, questions should always be asked after first stating what you know (often with evidence like code or irb output).

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com