I have a class (BaseClass) and a subclass (SubClass) that inherits from the BaseClass. One of the operations I want to perform is to send requests from the Base to the Sub but only if there is a method defined for it. Let me demonstrate this with some code:
BaseClass:
def extract_data extracted_data=Hash.new ['attr1','attr2','attr3'].each do |attr| extracted_data[attr] = self.send("extract_#{attr}") end return extracted_data end SubClass:
def extract_attr1 # do something and return a value end This works prefectly well if there is a method with that name in defined in the Subclass. If its not defined I will get an error. How can I check that a method is defined in a subclass before calling it?