This is an embarrassing mistake, because if I had RTFM'd for the ruby language then I wouldn't have had any problems, but in case anyone is frantically searching for the same answer, here's the issue:
Let's say you are subclassing a library class, like so:
class MyClass < ThirdPartyClass
end
Now, ThirdPartyClass defines an instance method called "party_on" (which returns "true" if it successfully parties, and false if otherwise). This is used many places throughout the code. You would like to override it in your subclass so that you can run an extra check before executing the method. If you come from another language where "super" is basically a pointer to the parent instance, you might write your code like this:
class MyClass < ThirdPartyClass
def party_on
if self.has_class_tomorrow
raise "No party tonight, must study!"
end
super.party_on
end
end
If you did this, you might be confused at the error output:
NoMethodError: undefined method `party_on' for true:TrueClass
What's going on here? Is my super class the "True" class that represents the boolean constant true? No, the deal is that ruby is a little different from that other language you're used to. "super" is not a pointer to the parent instance, it's a method call that executes the same method name that you are currently in on the parent class (basically it passes the message up one layer in the hierarchy). You can pass parameters to it and everything doing "super(parm1,parm2)". The correct way to write the above code is like this:
class MyClass < ThirdPartyClass
def party_on
if self.has_class_tomorrow
raise "No party tonight, must study!"
end
super
end
end
Hope someone benefits from that!
