bill walton wrote:
> On Thu, 2009-07-16 at 22:25 +0200, Älphä Blüë 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...
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to