To answer your question,
1. def author 2. author || NullUser.new 3. super 4. end
On line 1, you define the author method. Then, on line 2, you call this author method again! This continues to happen, and you get too high a stack level. The correct way to do this is:
def author super || NullUser.new end
So, you no longer call the author method inside yourself. You just call the superclass or return NullUser. If you cause a null error when calling super , add an extra nil check:
def author (super || NullUser.new) rescue NullUser.new end
The rescue operator will catch all the errors and then return NullUser.new, so you don’t have to worry about the super throwing an error.
EDIT:
Another way to deal with a super throwing exception that looks better:
def author (super rescue nil) || NullUser.new end
source share