Can these keywords in ruby be redefined? And what are the main purposes to do that?
They're not redefined. In ruby, a class/module is never 'closed' - i.e. you can just add new methods and override old ones. Some people call this 'monkey patching' and act like it's a bad thing. To rubyists, it's a powerful feature. Rails extends and modifies the core of ruby to add the features that we know and love. For example, if I wanted to add a method to all ActiveRecord objects for my application, I could just open up ActiveRecord and define it:
class ActiveRecord:Base def self.number_of_attributes @attributes.size end end
I could then use this method on any of my models: Person.number_of_attributes -> 3
Hope that helps,
Steve