Hey guys, busy learning ROR... I wasn't quite sure how to look for this problem on stackoverflow so sorry if this has been asked before :p
Basically I'm in the Console environment busy reading all the rows from a table into a variable and I noticed that you can reference the results by specifing my_object.id
OR my_object[:id]
.
Can someone tell me if there is a specific reason for this? Is one of these 'methods' deprecated or what is the reason for this?
Here is a code snippit: (assuming all has been set)
my_object = MyModel.find(:all)
my_object[1].id #returns => 'my value'
my_object[1][:id] # also returns => 'my value'
Which of these methods are best practice? Or is it purely a notation preference?
Thanks :)