I am a beginner in Ruby. I am providing below a code snippet which I want to know the meaning of the syntax of. I know the semantics, in a sense that I can run the full length code and see what happens. But I am not clear on the language construct itself.
class Product < ActiveRecord::Base
include ActsAsTree
self.primary_key = 'id'
acts_as_tree foreign_key: 'product_id'
Questions follow:
- Is
ActiveRecorda module provided byActiveRecordgem? - Is
ActiveRecord::Basea class contained inActiveRecordmodule? - Is
primary_keyan attribute ofActiveRecord::Baseclass? - The last line of the code confuses me the most.
acts_as_treeis the name of the gem. Why does it precede in the statement? And what the heck isforeign_key: 'product_id'? Why is there a colon(:) separator in between? What language construct does the statement represent?
acts_as_tree. I'd strongly consider boning up on some Ruby basics.acts_as_tree foreign_key: 'product_id'is equal toact_as_tree(:foreign_key => 'product_id')