One question that ran through my mind was how does the Ruby interpreter know that a method exists on a object if the definition is yet to be interpreted? Like, wouldn’t it matter whether you define the method first than use it, rather than use it then define it?
Share
It doesn’t know, and it doesn’t care – until execution. When a method call statement is executed, the interpreter looks to see if the class (object, not code!) has the named function. If it does not, it looks up the ancestor tree. If it does not find any, it calls the
method_missingmethod. If that is not defined, you get your error.If your function call does not get executed, you will not get any errors.