From: Jan Svitok Date: 2007-03-01T22:16:36+09:00 Subject: Re: Newbie Question On 3/1/07, Dick wrote: > Hi, > > I am new to Ruby. This is the very first class I am writing and it > doesn't seem that Ruby is designed to handle what I thought should work. > Why doesn't the below work? > > class Song < ActiveRecord::Base > @@dcounts = [] > > def Song.count(difficulty, artistid) > @@dcounts[difficulty][artistid] > end > > def Song.count=(difficulty, artistid, val) > @@dcounts[difficulty] ||= {} > @@dcounts[difficulty][artistid] = val > end > end > > Song.count(1, 3547) = 10 > > test.rb:14: parse error, unexpected '=', expecting $ > Song.count(1,3547) = 10 You can't have more then one argument to setter (var=) change it to def Song.set_count(difficulty, artistid, val) @@dcounts[difficulty] ||= {} @@dcounts[difficulty][artistid] = val end Song.set_count(1, 3547,10) Then, maybe you can create classes for each of the subhashes to encapsulate the functionality - but it depends on the purpose and the data. It's possible to write the code that you could write: Song.difficulty(1).artist(3547) = 10