Undef keyword in Ruby
Ruby provides a special keyword which is known as undef keyword. This keyword used to avoid the current working class from responding to calls to the specified named methods or variable. Or in other words, once you use under keyword with any method name you are not able to call that method. If you trying to call such type of method, then you will get an error message which says that undefined local variable or method. You can also undefined multiple methods using a single undef keyword.
Let us discuss this concept with the help of the given examples:
Welcome to GeeksforGeeks portal !! main.rb:26:in `<main>': undefined local variable or method `language' for main:Object (NameError)
Explanation: In the above example, we have two method, i.e, portal and language. Here, when we call portal method prints “Welcome to GeeksforGeeks portal !!”, but when we call language method it will gives an error massage that is undefine method ‘language’. Because we use undef keyword before language method that makes language method undefined.
main.rb:24:in `<class:Student>': undefined method `st_id' for class `Student' (NameError) from main.rb:7:in `<main>'