In Ruby when inheriting class beware of the expected value of self. The following example illustrates this caveat. class Log def self.priority Log.new(priority: true) end end   class Fishing < Log end   >> Fishing.priority => <#Log … > But… if you declare self.new the class with inherit from current class.   class Log def self.priority self.new(priority: true) end end   class Fishing < Log end   >> Fishing.priority #=> <#Fishing … > :)

Self is not always present in callbacks and the following demonstrates one such example in the way we create objects. Let’s assume we have a standard polymorphic example like the following. class Comment < ActiveRecord::Base   after_create :view_commentable   # … ommitted …   private   def update_commentables_cache raise commentable.inspect end   end 1) This example illustrates how to create a comment with self.commentable in the callback [3] pry(main)> Comment.create!(author_id: 1234, text: "party", commentable_type: "Post", commentable_id: post.id) (0.3ms) BEGIN …. (0.2ms) ROLLBACK … RuntimeError: #<Post id: 134, user_id: 12345 … > 2) But… if we add a create and add a comment to Post we lose scope. [4] pry(main)> post.comments << Comment.create!(author_id: 1234, text: "foo party") (0.4ms) BEGIN … (0.2ms)[…]