On Fri, Dec 30, 2005 at 05:51:35PM -0700, Bruce B. wrote:
Thanks. I now guess that a is neither a hash nor an array but rather
it is just an object of type object. Is that true?
No, from the code in your last post, each ‘a’ will be an object of type
Account, which should be a descendant of ActiveRecord::Base.
My problem is that a does not currently have a balance attribute and
so I wish to extend the object to include one. Is this possible? If
not, how can I convert my object to a hash so I can add this
attribute ‘balance’ that I require.
Keep well away from the idea of hashes. You don’t want them. If you
to add a new attribute, you can just add it to the database table which
backs the Account class (if you want to store that value in the
or else add an :attr_accessor balance to your class definition, which
create the necessary accessor methods to manipulate the instance
@balance in your Account objects.
If the previous paragraph was complete gibberish to you, you might be
served to pick up a copy of the pickaxe and learn some more Ruby
(or else my explanatory skills have gone badly downhill lately). I
imagine doing much at all with Rails without understanding the